Scala - object junit is not a member of package org - eclipse

I am doing the Scala course from Coursera.
I have a test file containing the following line:
import org.junit.runner.RunWith
Here, I get the following error:
Multiple markers at this line:
- object junit is not a member of package org
- object junit is not a member of package org
My question is similar to this one:
object scalatest is not a member of package org
I followed the answer by adding to my build.sbt:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
However, when I run eclipse in the scala console inside the root folder of my project I get:
<console>:11: error: not found: value eclipse
eclipse

Instead of build.sbt, you need to add the line above to the plugins.sbt file in your project folder. If it does not exist, you should create it.

Related

NullPointerException on XML.loadFile()

I am trying to load an xml file using scala-xml_2.12-1.0.6.jar but it gives me NullPointerEexception while loading
Following is my line of code to load xml
import scala.xml.XML
val xml = XML.loadFile("sample.xml")
I have decompiled this jar and is method is present in that jar but for some reasons it is unable to find it in code.
I have Scala 2.13.1 on my system but for this project I am using scala 2.12.1 and it is mentioned in mu built.sbt
scalaVersion := "2.12.1"
I have following dependency in my built.sbt for this xml package
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6"
If I copy and paste the same code to Scala interactive shell( scala 2.13.1) I get following error
import scala.xml.XML
^
error: object xml is not a member of package scala
did you mean Nil?
Can anyone please identify what am i doing wrong?
Thanks in advance.
I'm not sure how you are loading up the Scala REPL, but as mentioned in "How to use third party libraries with Scala REPL?", you should be launching the the REPL from SBT with sbt console. Your .sbt files will also need to be in scope.
The Scala REPL independently does not deal with .sbt files. They are 2 different tools.
Alternatively you could also install Ammonite-REPL which supports Magic Imports. You will be able to import Maven dependencies with import $ivy.
Scala 2.12 comes with scala-xml and you can remove that dependency as long as you run REPL with sbt console and not your native Scala REPL which is already # Scala 2.13. Otherwise you can also switch to Scala 2.13 for your SBT project.

import not found error for sbt.build file

I am in the learning process for Scala and sbt. I have an existing project I am starting with.
On the command line under top project folder, as soon as I enter the sbt command I get:
C:\Projects\aproject\build.sbt:1: error: not found: object scalariform
import scalariform.formatter.preferences._
C:\Projects\aProject\build.sbt:2: error: object sbt is not a member of package com.typesafe
import com.typesafe.sbt.SbtScalariform
I can't find an online reference for this specific error. I assume the second error is because of the first error.
The sbt.build file has these three imports:
import scalariform.formatter.preferences._
import com.typesafe.sbt.SbtScalariform
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
I have scala version 2.13.0
and sbt version 1.2.8
Add to project/plugins.sbt
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
and refresh the project.
https://github.com/sbt/sbt-scalariform

Idea SBT support: cannot resolve symbol in vanilla project

I am using Intellij UE 2017.3. The steps that I undertook were:
Create a new project from Lightbend templates
Check import sbt sources (tried without as well)
Try the suggested solutions from this thread
As a result in my build.sbt nothing seems to be imported, regardless of whether before or after trying the suggested fixes, (even the Dependencies object in /project folder).
Here is Dependencies object contents:
import sbt._
object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
}
I attach below screenshot with the errors and project structure. Note that in External Libraries scalatest version is different from scalaVersion, but former is correctly imported in Dependencies object.
The errors that appear are:
for Dependencies: Cannot resolve symbol
for settings: Cannot resolve reference settings with such signature, Cannot resolve symbol settings
for List: Type mismatch: expected: Def.SettingsDefinition,
actual Seq[Def.Setting[_]]
for name and libraryDependencies: too many
arguments for method settings
sbt.version is 1.1.1

Trouble adding Mapper as dependency in a Lift project

I am doing my first Lift project and want to add a database. Following a book, I added the following dependency to build.sbt:
"net.liftweb" %% "lift-mapper" % liftVersion % "compile",
And then, in Boot.scala, the import
import net.liftweb.mapper._
Now the project doesn't compile, with Boot.scala giving the error
object mapper is not a member of package net.liftweb
But other sources around the Internet seem to suggest that my imports are OK.
Where does the dependency problem come from?
It turned out that this is a problem of Eclipse, which cannot setup the dependencies correctly.
I had to close the project in Eclipse and delete the hidden files .classpath and .project. Then get into SBT and run
eclipse
(the project has to use the sbteclipse plugin as described in the Lift cookbook). This recreates the project files with the correct dependencies.
Afterwards, Eclipse compiled the code as expected. It seems this will be needed every time a change is made to build.sbt.

Package visible in Scala REPL but not in Eclipse in SBT project?

I have the following line in my build.sbt:
libraryDependencies += "org.bouncycastle" % "bcprov-jdk16" % "1.46"
When I go to REPL and launch my project there, the following works:
scala> import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.jce.provider.BouncyCastleProvider
scala> val a = new BouncyCastleProvider
a: org.bouncycastle.jce.provider.BouncyCastleProvider = BC version 1.46
But when I try to import the same package in Eclipse I get an error:
import org.bouncycastle.jce.provider.BouncyCastleProvider
// object bouncycastle is not a member of package org
Why is this happening?
Have you tried running sbt eclipse? That should create Eclipse project files, .classpath among them as well, which contains paths to dependencies.
Unless you use a version of Eclipse with support for dependencies under sbt, you'll have to execute sbt eclipse every time you've changed them.