SBT Scala Version Warning - scala

I started seeing the following warning messages when doing sbt build:
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.1, 2.11.7, 2.11.2, 2.11.6, 2.11.5, 2.11.0) -> 2.11.8
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
Why is this? I'm on sbt 0.13.11!
Did something change with the sbt version? I guess I was on 0.13.5 before and did not see any warning of this sort!

It means your project defines a Scala version smaller than 2.11.8, but sbt decided to increase it to 2.11.8 because one of the dependencies uses that version. It shouldn't matter because these versions are binary compatible. I guess it warns you because you might have deliberately used a smaller version because of some regression, and in that case you would need to force a smaller Scala version using the explanation. In other cases, just ignore the warning or increase your project's Scala version to the latest (2.11.8).

I'm not sure if adding / changing Scala version would be benign. So I just added the following to my build.sbt to get rid of the warnings:
evictionWarningOptions in update :=
EvictionWarningOptions.default
.withWarnTransitiveEvictions(false)
.withWarnDirectEvictions(false)
.withWarnScalaVersionEviction(false)

Related

scalafx in scala project intellij (unresolved dependencies path:)

i was compiling my scalafx code in intellij in a sbt file and they kept showing me this error, please help i tried everything but its still not working
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] stack trace is suppressed; run last update for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.scalafx:scalafx_2.13:8.0.192-R14
[error] Not found
[error] Not found
[error] not found: /Users/xxxxx/.ivy2/local/org.scalafx/scalafx_2.13/8.0.192-R14/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/org/scalafx/scalafx_2.13/8.0.192-R14/scalafx_2.13-8.0.192-R14.pom
this is my built.sbt
name := "practical4b"
version := "0.1"
scalaVersion := "2.13.1"
// https://mvnrepository.com/artifact/org.scalafx/scalafx
libraryDependencies += "org.scalafx"%%"scalafx"%"8.0.192-R14"
The problem here is that there is no release of ScalaFX 8/R14 that works with Scala 2.13.
Each Scala release, with the exception of bug-fix releases, has different binary compatibility requirements. So if you're using a Scala-built library with, say, Scala 2.13, you need the build of that library created for the same Scala version. Libraries created from Java code typically have binary compatibility with any version of Scala.
To determine which Scala versions are supported, they are listed in the column under Scala on Maven Central (the site linked to in your code above the libraryDependencies property):
You can resolve this problem either by switching to Scala 2.12, by changing the Scala version as follows:
scalaVersion := "2.12.12"
Or, you can use a more recent version of ScalaFX, that will work with Scala 2.13, by changing the library dependency as follows:
libraryDependencies += "org.scalafx" %% "scalafx" % "12.0.2-R18"
to use R18, or:
libraryDependencies += "org.scalafx" %% "scalafx" % "14-R19"
for R19.
A lot will depend upon which version of Java you are using. If you need to use Scala 2.13, with one of the more recent ScalaFX releases, I would recommend using Java 11 LTS. If you must use Java 8, then stay with the ScalaFX 8/R14 release and use Scala 2.12. Let me know if you have any questions.

sbt configuring -- or using an already installed -- newer version of Scala

When I install the latest version of sbt (v0.13.9) and then run the following to download scala and associated libraries:
jdoe$ sbt test
jdoe$
jdoe$ sbt console
[info] Set current project to nmvega (in build file:/home/jdoe/)
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
I get Scala version 2.10.5, as seen above.
How can I get sbt to build with (or use a separately installed) scala version, say v2.12.0-M3 ? I can't find instructions for this.
Thank you in advance.
As you can see in documentation SBT provides many ways to Configure and use Scala
Set the Scala version used for building the project
The scalaVersion configures the version of Scala used for compilation. By default, sbt also adds a dependency on the Scala library with this version. See the next section for how to disable this automatic dependency. If the Scala version is not specified, the version sbt was built against is used. It is recommended to explicitly specify the version of Scala.
For example, to set the Scala version to "2.9.2",
scalaVersion := "2.9.2"
Disable the automatic dependency on the Scala library
sbt adds a dependency on the Scala standard library by default. To disable this behavior, set the autoScalaLibrary setting to false.
autoScalaLibrary := false
Temporarily switch to a different Scala version
To set the Scala version in all scopes to a specific value, use the ++ command. For example, to temporarily use Scala 2.8.2, run:
> ++ 2.8.2
Use a local Scala installation for building a project
Defining the scalaHome setting with the path to the Scala home directory will use that Scala installation. sbt still requires scalaVersion to be set when a local Scala version is used. For example,
scalaVersion := "2.10.0-local"
scalaHome := Some(file("/path/to/scala/home/"))
Can you post your build.sbt please.
You should be able to declare the Scala by adding the following to build.sbt file
scalaVersion := "2.11.7"

In SBT 0.13, does scalaVersion still control the version of scala used for compile, run and test?

When upgrading our build from 12.4 to 13.1 I observed that although the build specified scalaVersion := "2.10.2", the resulting archive (created via the sbt-pack plugin) contained scala-library-2.10.3.jar. A quick check confirmed that the 12.4 build was including scala-library-2.10.2.jar.
It appears that sbt 0.13 included a change to treat the scala libraries as normal dependencies, with the consequence that if a project dependency was built with a later 2.10.x version of scala then that transitive dependency will "win" the ivy dependency resolution conflict resolution, and the compile, test and run classpaths will contain the later version of scala libraries.
Is this the desired behavior, or a bug in sbt 0.13?
If the desired behavior, then does that mean I have to use the mechanisms to "force/override" the conflict resolution to use my desired version of the scala libraries? (If so, the scalaVersion configuration setting seems a bit pointless....)
Here is an extremely minimal test case to illustrate the behavior:
test-proj/
build.sbt
project/
build.properties
build.sbt:
scalaVersion := "2.10.2"
//scalaVersion := "2.10.3"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.0"
//libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.2.4"
build.properties:
sbt.version=0.13.1
Akka 2.2.4 was built against scala 2.10.2, so firing up sbt and running "update", "show update", "show compile:dependencyClasspath", "show test:dependencyClasspath" and "show runtime:dependencyClasspath" all show scala-library 2.10.2 on the classpath.
Switching to Akka 2.3.0, which was built against scala 2.10.3, results in scala-library 2.10.3 appearing on all the classpaths, and "show update" clearly shows 2.10.2 being evicted by Ivy's conflict resolution.
Interestingly (and inconsistently), entering the REPL in both cases (via the sbt console command) results in scala 2.10.2 being utilized.
According to the docs, in sbt 0.13
The scalaVersion configures the version of Scala used for compilation. By default, sbt also adds a dependency on the Scala library with this version.
Based on that, I would expect the compilation classpath above to include 2.10.2 in both circumstances.
However, the release notes for 0.13 say
Scala dependencies (like scala-library and scala-compiler) are now resolved via the normal update task
which does at least explain the observed behavior.
sbt 0.13.0 Changes
You wrote:
It appears that sbt 0.13 included a change to treat the scala libraries as normal dependencies, with the consequence that if a project dependency was built with a later 2.10.x version of scala then that transitive dependency will "win" the ivy dependency resolution conflict resolution, and the compile, test and run classpaths will contain the later version of scala libraries.
sbt 0.13.0 Changes has somewhat conflicting note on this issue. Features, fixes, changes with compatibility implications section says:
sbt no longer overrides the Scala version in dependencies. This allows independent configurations to depend on different Scala versions and treats Scala dependencies other than scala-library as normal dependencies. However, it can result in resolved versions other than scalaVersion for those other Scala libraries.
Resolving Scala dependencies section says:
Scala dependencies (like scala-library and scala-compiler) are now resolved via the normal update task.
(Emphasis added by Eugene) So the quick answer to your "Is this the desired behavior, or a bug in sbt 0.13?" as you've already answered yourself is: In sbt 0.13.x, this behavior seems to be intended. Akka 2.3.0 depends on scala-library 2.10.3, and Ivy has evicted scala-library 2.10.2 in favor of 2.10.3.
dependencyOverrides
To workaround this, you can use dependencyOverrides setting as follows:
dependencyOverrides += "org.scala-lang" % "scala-library" % scalaVersion.value
Before:
sbt-so-22551430> show fullClasspath
[info] List(... Attributed(/Users/xxx/.sbt/0.13/boot/scala-2.10.3/lib/scala-library.jar) ...)
After:
sbt-so-22551430> show fullClasspath
[info] List(... Attributed(/Users/xxx/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.10.2.jar) ...)
Is this behavior desirable?
Your question was not whether if this is by design, but if this is desirable. I think the current behavior is quite surprising, and sbt should at least improve on notifying the build users of this behavior. And perhaps change its default Ivy conflict management policy to force() the version specified in scalaVersion. Here are two GitHub issues I created:
shell should display all evicted libraries on start up #1200
provide some means of forcing scala-library version to scalaVersion #1201

sbt is using wrong scala version rather than using the configuration in build.sbt

I have put these in the build.sbt file under current project's root directory
scalaHome := Some(file("/Users/ddam/scala-2.10.2"))
scalaVersion := "2.10.2"
And I ran sbt using
$ sbt --version
sbt launcher version 0.12.4
But still, I am seeing both the wrong version for sbt and scala when a particular dependency cannot be resolved
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.4.0 (sbtVersion=0.12, scalaVersion=2.9.2)
Please help me.
It looks like sbteclipse requires SBT 0.13.0, and you are using version 0.12.4.
You can specify the SBT version by following the directions on this page.
Some other notes: You probably want to use Scala 2.10.3, not 2.10.2.
Also, it's strange to specify scalaHome; usually SBT will automatically fetch the needed Scala jars for you.
So to bootstrap a Scala environment, all you need to have installed are SBT and a JDK.
EDIT: (addressing comment below):
When you build code with SBT, you may actually use two different versions of Scala.
There is the version for SBT (what version of Scala the build system runs on), and the version for the code in your project (what version of Scala your code will run on).
The Scala version for SBT is determined by the SBT version you use.
If you use 0.12.4, SBT will run on Scala 2.9.3.
If you use 0.13.0, SBT will run on Scala 2.10.3.
You control the SBT version by following these instructions.
To control the version of Scala your project will run on, you can set scalaVersion in <projectRoot>/build.sbt.
So, you're getting that error because you're using SBT 0.12.4, which uses Scala 2.9.3.
SBT tries to find the sbteclipse plugin for 2.9.3, but it doesn't exist because it requires SBT 0.13.0 (=> Scala 2.10.3).
It seems you've correctly specified the use of Scala 2.10.2 for compiling your project.
sbt 0.12.4 always uses Scala 2.9.x to compile the build files (i.e. build.sbt and the stuff under project/). This means that plugins for sbt 0.12.x must also be compiled against 2.9.x, which explains what you're seeing.
sbteclipse 2.4.0 requires sbt 0.13. Try sbteclipse 2.2.0 if you want to stay on sbt 0.12.4.
emchristiansen's answer has good additional points.

How to change Scala version for build definition?

I'm developing a simple SBT project that includes InputTasks for benchmarking Scala Parallel collections.
I have defined the InputKeys and started writing the tasks when I encountered a problem.
Since my benchmarks require Scala 2.10.0-M5, I tried doing this in my build.sbt:
name := "scala-parallel-collection-benchmark"
version := "1.0.0"
organization := "com.google.summer"
scalaVersion := "2.10.0-M5"
However, at compilation I get the following error:
[info] Loading project definition from C:\Users\Administrator\scala-parallel-collection-benchmark\project
[info] Compiling 1 Scala source to C:\Users\Administrator\scala-parallel-collection-benchmark\project\target\scala-2.9.1\sbt-0.11.3\classes...
[error] C:\Users\Administrator\scala-parallel-collection-benchmark\project\Build.scala:47: value tasksupport is not a member of scala.collection.parallel.mutable.ParArray[Int]
[error] collection.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool(par))
[error] ^
[error] one error found
[error] {file:/C:/Users/Administrator/scala-parallel-collection-benchmark/project/}default-e0b2a2/compile:compile: Compilation failed
It appears that it still uses Scala 2.9.1 to compile it.
How can I set up SBT so it compiles my code using Scala 2.10.0-M5?
scalaVersion only impacts the version of Scala used to compile the "actual" source code (usually located in src/...). Your error comes from a part of the build definition (under project/), which is always compiled with the Scala version that sbt was built with.
You can't modify the version of Scala that is used to to compile the project definition, because it must be a version binary compatible with the version used to compile SBT itself. There's some flexibility being studied in this regard, but, right now, it's fixed.
The setting scalaVersion will change the version of Scala used to compile the project itself. The project can be compiled with completely different versions and, in fact, you can even have SBT compile your project with multiple Scala versions.
you can change the scala version in file "project/build.properties"
e.g. sbt.version=0.11.2