I'm new to Scala and Heroku and I'm following the Heroku getting-started guide.
I'm using Mac (10.14.6) and followed the instructions here to install sbt and play.
I am now on Declare app dependencies but when I type the sbt compile stage command I get the following error:
$ sbt compile stage
[info] welcome to sbt 1.3.13 (AdoptOpenJDK Java 11.0.8)
[info] loading project definition from /Users/jack/scala-getting-started/project
/Users/jack/scala-getting-started/build.sbt:5: error: not found: value PlayScala
lazy val root = (project in file(".")).enablePlugins(PlayScala)
^
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
The build.sbt file (provided automatically) is
name := """play-getting-started"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
jdbc,
cache,
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
ws
)
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _ )
How can I fix this error?
Thank you.
Related
I'm compiling a multi-part Scala project. It's not that large, but some of it is Scala 2.13 and some is Scala 3.
Attempting to compile generates the fatal error [UNRESOLVED DEPENDENCIES:
base#base_2.12;0.1.0-SNAPSHOT: not found]
The thing is, the string {0.1.0-SNAPSHOT} doesn't occur anywhere in my build.sbt or anywhere else. It used to be there, but it's long gone. I assume some update cache contains it, but I've been unable to find it.
Here is my {build.sbt}:
ThisBuild / libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
ThisBuild / Compile / scalacOptions ++= Seq("--deprecation")
ThisBuild / Test / logBuffered := false
ThisBuild / Test / parallelExecution := false
lazy val scala213 = "2.13.5"
lazy val scala212 = "2.12.13"
lazy val scala3 = "3.0.0-RC2"
lazy val supportedScalaVersions = List(scala213, scala3)
lazy val root = (project in file("."))
.aggregate(top, trans, base)
.settings(
name := "toysat"
)
lazy val top = (project in file("top"))
.settings(
name := "main",
scalaVersion := scala213,
scalacOptions += "-Ytasty-reader",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
)
.dependsOn(trans, base)
lazy val trans = (project in file("trans"))
.settings(
name := "trans",
Compile / scalaVersion := scala3,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
).
dependsOn(base)
lazy val base = (project in file("base"))
.settings(
name := "base",
scalaVersion := scala213,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
Most questions of this ilk on stackoverflow are about downloading remotely defined modules. The problem I'm having is that sbt cannot find an obsolete version of one of my (freshly compiled) modules.
and here is the sbt command output (this is an Emacs buffer):
sbt:toysat> reload
[info] welcome to sbt 1.5.5 (AdoptOpenJDK Java 1.8.0_292)
[info] loading project definition from /Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/project
[info] loading settings for project root from build.sbt ...
[info] set current project to toysat (in build file:/Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/)
sbt:toysat> compile
[info] compiling 4 Scala sources to /Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/base/target/scala-2.13/classes ...
[warn]
[warn] Note: Unresolved dependencies path:
[info] done compiling
[error] stack trace is suppressed; run last trans / update for the full output
[error] (trans / update) sbt.librarymanagement.ResolveException: Error downloading base:base_2.12:0.1.0-SNAPSHOT
[error] Not found
[error] Not found
[error] not found: /Users/drewmcdermott/.ivy2/localbase/base_2.12/0.1.0-SNAPSHOT/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/base/base_2.12/0.1.0-SNAPSHOT/base_2.12-0.1.0-SNAPSHOT.pom
[error] Total time: 25 s, completed Jul 28, 2021 11:06:18 PM
The 25 seconds were consumed compiling the 4 files in the base subproject, apparently successfully. I think it's when sbt tries to compile the trans subproject that it runs into trouble.
Here's a partial stack trace. It means nothing to me except that Coursier is involved.
sbt:toysat> last trans / update
[debug] not up to date. inChanged = true, force = false
[debug] Updating trans...
[warn]
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading base:base_2.12:0.1.0-SNAPSHOT
[error] Not found
[error] Not found
[error] not found: /Users/drewmcdermott/.ivy2/localbase/base_2.12/0.1.0-SNAPSHOT/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/base/base_2.12/0.1.0-SNAPSHOT/base_2.12-0.1.0-SNAPSHOT.pom
[error] at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:258)
[error] at lmcoursier.CoursierDependencyResolution.$anonfun$update$38(CoursierDependencyResolution.scala:227)
[error] at lmcoursier.CoursierDependencyResolution$$Lambda$4262/0x0000000000000000.apply(Unknown Source)
[error] at scala.util.Either$LeftProjection.map(Either.scala:573)
[error] at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:227)
[error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:59)
It seems clear that some cache somewhere is holding onto the string 0.1.0-SNAPSHOT, but there are an ungodly number of caches. I've tried deleting several, but I haven't found the relevant one.
Can someone explain how to recover from a situation like this?
Your base project is only compiled for Scala 2.13 whereas it is defined as a dependency (using dependsOn) of trans which targets Scala 3.
You should cross-build your base project for Scala 2.13 and 3 (and maybe 2.12 according to your error message even though I don't see any use of Scala 2.12 in what you shared).
Edit: Scala 2.13 and 3 are compatible, so the issue should only happen if a dependency is built only for 2.12.
I am not answering my own question because I'm a narcissist, but because I can't say what I want in a comment. Plus editing the original question would bury possibly useful information in an odd place. I've upvoted and approved #GaelJ's answer.
My build.sbt doesn't look that different. The differences may be encapsulated by showing the revised trans subproject definition:
lazy val trans = (projectMatrix in file("trans"))
.settings(
name := "trans",
version := "0.3",
// I thought this line was unnecessary, but without
// it sbt doesn't understand the command trans / compile --
Compile / scalaVersion := scala3,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
)
.jvmPlatform(scalaVersions = Seq(scala213))
.dependsOn(base)
SBT stucks for an hour at downloadinng a library and showing speed = 0, here is the output:
sbt kafka/compile [process_args] java_version = '8'
# Executing command line: java
-XX:ReservedCodeCacheSize=128m
-Xms2g
-Xmx4g
-Xss4m
-XX:+UseG1GC
-XX:MaxMetaspaceSize=1g
-jar /usr/local/Cellar/sbt/1.2.8/libexec/bin/sbt-launch.jar kafka/compile
[info] Loading global plugins from /Users/minhthai/.sbt/1.0/plugins [info] Loading settings for project kafka_spark_streaming-build from assembly.sbt,plugins.sbt ... [info] Loading project definition from /Users/minhthai/coding/kafka_spark_streaming/project [info] Loading settings for project kafka_spark_streaming from build.sbt ... [info] Set current project to kafka_spark_streaming (in build file:/Users/minhthai/coding/kafka_spark_streaming/) [info] Fetching artifacts of kafka https://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.11.12/scala-reflect-2.11.12.jar
33.6% [... ] 1.5 MiB (0 B / s)
Here is my build file
ThisBuild / scalaVersion := "2.11.12"
ThisBuild / version := "0.0.1"
lazy val spark = project
.settings(
assembly / mainClass := Some("Main"),
assembly / assemblyJarName := "spark.jar",
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-sql" % "2.4.3",
"org.apache.spark" %% "spark-sql-kafka-0-10" % "2.4.3" % "provided"
)
)
lazy val kafka = project
.settings(
libraryDependencies ++= Seq(
"org.apache.kafka" % "kafka-clients" % "2.2.0"
)
)
I tried removing the cache at ~/.ivy2 and run again but the message is exactly the same, the download stops at 33.6%. I can still download other library and can manually download this jar file in browser.
So what can I do to resolve this issue? If no, is there a way to add this jar file manually?
Sbt has those kinds of downloading problems...restarting the process (Ctrl+C) and running again might help.
If it doesn't work, you can add the jar manually like this:
libraryDependencies += "org.scala-lang" % "scala-reflect" % "2.11.12" from "http://central.maven.org/maven2/org/scala-lang/scala-reflect/2.11.12/scala-reflect-2.11.12.jar"
You can look at the sbt official documentation here.
I found the problem and it is silly. I use coursier plugin to handle dependencies and I should have deleted the cache of coursier instead of ivy2. On Mac, it is at ~/Library/Caches/Coursier/v1 (doc).
I just followed the getting started page of Spark and tried to run the simpleApp.
My Spark version : 2.3
Scala version in REPL: 2.11.8
This is the build.sbt file:
name := "Simple Project"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.3.0"
When I run sbt package, First I get some of conflicts warnings. Then there's this error
not found: value SparkSession
[error] val spark = SparkSession.builder.appName("Simple Application").getOrCreate()
What could I be missing? In the target folder, it shows scala 2.12. I wonder why.
I am trying to run a simple command sbt package but its get failed due to following error given below(bold command below). I will be thankful if anyone solve my problem? My spark version is 2.0 and scala version is 2.11.8 and using jdk 1.7 on centOS cloudera
[root#hadoop first]# vim build.sbt
name := "First Spark"
version := "1.0"
organization := "in.goai"
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.1"
resolvers += Resolver.mavenLocal
[root#hadoop first]# ls
build.sbt project src
**[root#hadoop first]# sbt package**
[info] Loading project definition from /home/training/Documents/workspace_scala/first/project
[info] Updating {file:/home/training/Documents/workspace_scala/first/project/}first-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
/home/training/Documents/workspace_scala/first/build.sbt:2: error: eof expected but ';' found.
version := "1.0"
^
[error] Error parsing expression. Ensure that settings are separated by blank lines.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
Just enter blank spaces between each line in your debt file. Hope that helps.
name := "First Spark"
version := "1.0"
organization := "in.goai"
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.1"
resolvers += Resolver.mavenLocal
I am using Playframework 2.5.4 to serve as REST API endpoint in default sbt build, compile & run with activator.
This play module imports a core module in local maven (3.9), where types were defined. Such as:
package com.myCompany
case class User(
id: Option[UUID] = None,
username: String
)
Then play controller package will import com.myCompany.User.
Issue is, when activator compiles, it gives unknown parameter name: username
If I placed case class in play's models package, it compiles without error.
Below is my build.sbt
name := """api"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
filters,
"com.myCompany" % "core" % "1.0-SNAPSHOT"
)
routesGenerator := InjectedRoutesGenerator
resolvers ++= Seq(
"scalaz-bintray" at "http://dl.bintray.com/scalaz/releases",
Resolver.mavenLocal
// "Local Maven Repository" at "file:///home/pocheng/.m2/repository"
)
I suspect build.sbt file is having issue. Would appreciate any pointer. Thanks.