Use SBT 1.3.x with Scala 2.13.8 - scala

After upgrading the Scala version to 2.13.8 (from 2.13.3) of my Scala project, the following error gets at load time:
[error] java.lang.NoSuchMethodError: 'sbt.internal.util.Init$Initialize sbt.Def$.ifS(sbt.internal.util.Init$Initialize, sbt.internal.util.Init$Initialize, sbt.internal.util.Init$Initialize)'
[error] Use 'last' for the full log.
Upgrading to SBT 1.4.x fixes this issue. But I can't upgrade to SBT to 1.4.x and want to use SBT 1.3.13.
How can I achieve this?

Related

When is there a sbt version for 2.13?

I would like to develop a sbt plugin that has dependencies that are only available for Scala 2.13.
I found on https://github.com/sbt/sbt/issues/5032 this list:
SBT 0.x runs only on Scala 2.10.x
SBT 1.x runs only on Scala 2.12.x
SBT 2.x will run only on Scala 2.13.x or 3.0.x
SBT 3.x will run only on Scala 3.0.x or Scala 3.1.x
Where the last two lines was a guess by the author mr-git.
However I did not find any other glue if there is actually a version for Scala 2.13.
Does anybody know?
Update: Added it here: https://discuss.lightbend.com/t/when-is-there-a-sbt-version-for-2-13/5623
If afraid you are out of luck. Your plugin needs to be binary compatible with the SBT, which currently means 2.12 for SBT 1.x.x or 2.10 for SBT 0.13.x. There is no trace of any SBT 2 version anywhere on the Internet, certainly no such version exists in the SBT GitHub repository
The situation was similar with Scala 2.11 before, see Does sbt build against scala 2.11? and What's the relationship of the versions of scala when I use sbt to build a scala project?

Getting "Internal error: Scala instance doesn't exist or is invalid" when trying to run a worksheet in IntelliJ IDEA

I'm trying to get Scala set up for a Coursera course on Ubuntu, and I've followed their instructions by installing open-jdk 1.8, sbt (sbt about says v1.0.2), and IntelliJ Idea. I've set up an sbt project with a HelloWorld Scala worksheet in src/main/scala that just says "Hello, world", but when I try to evaluate the worksheet, I get the error
Internal error: Scala instance doesn't exist or is invalid: version unknown, library jar: /home/[my username]/.ivy2/cache/jline/jline/jars/jline-2.14.5.jar, compiler jar: /home/[my username]/.ivy2/cache/org.scala-lang.modules/scala-xml_2.12/bundles/scala-xml_2.12-1.0.6.jar
followed by a longer trace. Is there a setup step I'm missing? The project seems to point to Java v1.8 in the Project Structure dependencies, and in the "Libraries" tab I see SBT set to Scala v2.12.
I've just had the same problem with macOS Sierra.
I solved after noticing that in my build.sbt I had:
name := "myScalaTests"
version := "0.1"
scalaVersion := "2.12.4"
but prompting sbt about, my scala version was different.
sbt about
[warn] No sbt.version set in project/build.properties, base directory: /Users/myUser/projects
[info] Set current project to projects (in build file:/Users/myUser/projects/)
[info] This is sbt 1.0.2
[info] The current project is {file:/Users/myUser/projects/}projects 0.1-SNAPSHOT
[info] The current project is built against Scala 2.12.3
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbt.plugins.Giter8TemplatePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.3
so I changed the version of scala in the build.sbt accordingly, ant it worked.
The same internal error can be caused by a version mismatch between the sbt launcher and the project sbt version, as described here:
Internal error: Scala instance doesn't exist or is invalid
In my project, there was no scala version mismatch, but downloading the latest sbt launcher and restarting my session resolved the issue.

SBT: how to use scala 2.11 libraries in scala 2.12 project

I'm trying to upgrade my project to use scala 2.12
However, I use some libraries, which don't have 2.12 versions
(mongoquery-casbah, salat).
If I force to use 2.11 versions of those libraries
("com.github.salat" % "salat_2.11" % "1.10.0", "com.github.limansky" % "mongoquery-casbah_2.11" % "0.5"), I get error:
[error] Modules were resolved with conflicting cross-version suffixes in {file:/C:/work/GeneASS/}dao:
[error] org.scala-lang.modules:scala-parser-combinators _2.11, _2.12
How can I resolve this problem?
The only way is to recompile the library for scala 2.12. This of course requires that any transitive dependencies of the library are also 2.12 compatible.
Scala source code is mostly compatible between versions but compiled byte code is not so you need to build a seperate artifact for every scala version you want to support.

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.

Cannot find sbt launcher 0.11.2

I have a Play 2.0 app that uses sbt 0.11.2. However when I set up a new Play server, it grabbed the latest version of sbt 0.11.3. Now when I run sbt compile on the new server, it complains
Detected sbt version 0.11.2
Cannot find sbt launcher 0.11.2
Please download:
/sbt-launch.jartypesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2
/sbt-launch.jarc2-user/.sbt/.lib/0.11.2
I tried downloading sbt-launch 0.11.2 and putting in the same folder as sbt but still get the same error. Incidentally, is there a difference between play compile vs. sbt compile because play compile works.
Yes I think there is a difference between play compile and sbt compile, if your sbt script uses a different SBT version, in your case vertion 0.11.2 rather than Play's 0.11.3.
Perhaps you should start using SBT 0.11.3 instead?
I just upgraded to Play 2.1-SNAPSHOT (Git rev. f7de038a48, Fri May 25) which uses SBT 0.11.3, and I had to make this change in project/build.properties:
Change from: sbt.version=0.11.2
to: sbt.version=0.11.3
And I linked my SBT bash script to the one included with Play, i.e. 0.11.3 not 0.11.2.
If you're compiling Play20 from source, after running the ./build command in ./Play20/framework, you'll be in the Play shell.
Run the command about and you can check what version of sbt is being run.
> about
[info] This is sbt 0.12.0
[info] The current project is {file:/home/jw/code/Play20/framework/}Root
[info] The current project is built against Scala 2.9.2
[info] Available Plugins: com.typesafe.tools.mima.plugin.MimaPlugin, com.typesafe.sbtscalariform.ScalariformPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
Then in your project directory, change the ./project/build.properties to the correct version.