Cannot find sbt launcher 0.11.2 - scala

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.

Related

SBT by default installing 1.0.3 version over 0.13.6

I am trying to install SBT 0.13.6 version in my ubuntu. For this I do the following steps:
wget http://dl.bintray.com/sbt/debian/sbt-0.13.6.deb
sudo dpkg -i sbt-0.13.6.deb
sudo apt-get update
sudo apt-get install sbt
After installing, when I check the sbt version, it shows version 1.0.3.
Here is the command:
hadoop#localhost:~$ sbt about
Getting org.scala-sbt sbt 1.0.3 ...
:: retrieving :: org.scala-sbt#boot-app
confs: [default]
69 artifacts copied, 0 already retrieved (22027kB/913ms)
Getting Scala 2.12.4 (for sbt)...
:: retrieving :: org.scala-sbt#boot-scala
confs: [default]
5 artifacts copied, 0 already retrieved (18986kB/225ms)
[info] Loading project definition from /home/hadoop/project
[info] Set current project to hadoop (in build file:/home/hadoop/)
[info] This is sbt 1.0.3
[info] The current project is {file:/home/hadoop/}hadoop 0.1-SNAPSHOT
[info] The current project is built against Scala 2.12.4
[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.4
And my Scala version is not 2.12.4; it's 2.11.8. Why is it showing wrong versions?
hadoop#localhost:~$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL
Did I made any mistake?
SBT - whichever version you have installed - will download a project-specific version of SBT when it runs. If no such version is specified, it will use the installed version. If you want a particular project to use SBT 0.13.6, then you create a file called ./project/build.properties (relative to your project's root directory, which will be /home/hadoop/project/build.properties in this particular case) with the following content:
sbt.version=0.13.6
SBT will then download that version and will use it to build your project.
Consequently, I strongly recommend that you always install the latest version of SBT on your machine, since that will simplify matters going forward.
BTW, I notice that you used dpkg to install a specific SBT version, but you then used apt-get install sbt - which will likely install the latest SBT release (I'm guessing release 1.0.3) for your version of Ubuntu, replacing the version you installed via dpkg. What was the output from those commands? Alternatively, your /home/hadoop/project/build.properties file - if present -
may be specifying SBT version 1.0.3.
One other thing to consider: the sbt command should be executed from a project directory - a directory that contains just your project's sources. It's not a good idea to run sbt from your HOME folder, as it will leave some output folders behind (such as ./project, ./target, etc.)
When compiling Scala sources, SBT will use the version specified in your SBT build file (or the version used to build the SBT version being used if that property is undefined) - it does not use any installed versions of Scala that you may have on your machine.
If you want to use Scala 2.11.8, then add the following line to your SBT build file:
scalaVersion := "2.11.8"
I strongly recommend that you review the SBT documentation on its web-site.

scala sbt version of plugin

I need to run a sbt plugin compiled for scala 2.11.
However, sbt tries to download the plugin for scala 2.12. How I force sbt to use scala 2.11?
ps: adding scalaVersion := "2.11.11" to build.sbt does not solve the problem, as the sbt plugin is not affected by this.
You cannot choose what Scala runtime is the SBT built against, you need to use the version compatible with the SBT you have. The only choice you have is which SBT version you use. See also How to change Scala version for build definition?
Sbt 1.x.x requires you to use Java 8 and Scala 2.12 - see SBT 1.0.0
sbt 1.0 uses Scala 2.12 for build definitions and plugins. This also requires JDK 8.
Previous 0.13 versions used Scala 2.10, see 0.13.1 notes:
The Scala version for sbt and sbt plugins is now 2.10.3.
There is no version using 2.11.x

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 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.

Why version of SBT is playing role in name of fully qualified dependency?

Why version of SBT is playing role in name of fully qualified dependency ?
I thought it only depends on version of Scala.
Here is example.
build.sbt has scalaVersion set to 2.10.2
build.properties has sbt.version set to 0.12.1
plugins.sbt has plugin dependency "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1"
If I build it I see following in the log:
[info] Resolving com.github.siasia#xsbt-web-plugin_2.9.2;0.12.0-0.2.11.1 ...
But if I change sbt.version set to 0.13.0-RC5 SBT fails to find this plugin and says in the log
[info] Resolving com.github.siasia#xsbt-web-plugin_2.10;0.12.0-0.2.11.1 ...
Why did it change scala version if it remains 2.10.2 in my config ? How to fix it ?
sbt projects are recursive, so each layer has its own settings(including scala version and classpath) (see http://www.scala-sbt.org/0.13.0/docs/Getting-Started/Full-Def.html )
sbt plugins are just regular libraries which depend on sbt, hence the plugins need to be cross-built across sbt versions (and each sbt version may require different scala version)
addSbtPlugin function takes care of that and resolves an appropriate artifact for current sbt and scala
siasia#xsbt-web-plugin is not really maintained anymore and it does not have versions for sbt 0.13, use https://github.com/JamesEarlDouglas/xsbt-web-plugin as a replacement