import not found error for sbt.build file - scala

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

Related

Can't find Spark libraries when using Eclipse

I used to code Scala within the terminal, but now I'm trying
with the ScalaIDE for Eclipse.
However, I've got one big problem:
error: not found: value sc
I've tried to add those libraries
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
But then it displays:
object apache is not a member of package org
So I don't know what to do....
In my IntelliJ project my build.sbt is pretty empty:
name := "test"
version := "1.0"
scalaVersion := "2.11.7"
is it a sbt project? make sure you have eclipse plugin for scala/sbt, and import it as a sbt project.
also, add the dependency on the build.sbt
nevertheless, I prefer Intellij :)

Scala - object junit is not a member of package org

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.

Repl showing error: object async is not a member of package scala on import

I am using scala 2.11.7 Repl (ubuntu) when trying to do this import I am getting :
scala> import scala.async.Async._
<console>:18: error: object async is not a member of package scala
import scala.async.Async._
^
how can I fix that ?
scala-async is not part of Scala standard library. You need to import the module in your project.
If you use sbt, you can add the following to your build file.
libraryDependencies += "org.scala-lang.modules" %% "scala-async" %
"0.9.5"
Check out this PR about the lack of information about this.
Hope this helps!
Use the following command to load the jar into classpath,
scala -classpath jarname.jar

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.

SBT can't resolve dependency in build definition

I'm making an SBT task that needs to make a multipart POST request to a certain server. I want to use Dispatch to make the request. I have the following in build.sbt at the top level of my project:
libraryDependencies ++= Seq(
"net.databinder.dispatch" %% "dispatch-core" % "0.9.5"
)
The task definition is in project/Build.scala. I have
import sbt._
import Keys._
import dispatch._
object SubmitBuild extends Build {
...
}
I get the following error message:
[error] /Users/ken/xxxxtools/project/Build.scala:3: not found: object dispatch
[error] import dispatch._
[error] ^
If I remove import dispatch._ then sbt will compile. I know I have Dispatch installed. Why can't SBT find it?
If you want to make references in Build.scala to some dependency it has to be declared in build's project not in the "project project". Meaning that it should be project/build.sbt.
It turns out that project/Build.scala is also a SBT project in the same way your project is.
SBT authors give a very good explanation in sbt is recursive.