When I run sbt on one project directory, it issues Detected sbt version 0.12.1 when starting off.
Typing about and it repeats that version.
However, running sbt in a different project directory identifies its version as 0.11.3.
This reproduces even within the same terminal session. The version just varies per project directory. Couldn't find any explicit part in the build.sbt file that would cause this.
What could explain this?
In my case I'd like to use sbt 0.12.1 in both cases, how can I force that version being used also for the later project?
The project is a SBT multi-project and since each subproject is a separate project you can use project/build.properties to set different versions of SBT. The command is simply project-specific.
jacek:~/sandbox/stackoverflow
$ mkdir sbt-sample-project
jacek:~/sandbox/stackoverflow
$ cd sbt-sample-project
jacek:~/sandbox/stackoverflow/sbt-sample-project
$ tree
.
0 directories, 0 files
jacek:~/sandbox/stackoverflow/sbt-sample-project
$ sbt about
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to sbt-sample-project (in build file:/Users/jacek/sandbox/stackoverflow/sbt-sample-project/)
[info] This is sbt 0.13.0
[info] The current project is {file:/Users/jacek/sandbox/stackoverflow/sbt-sample-project/}sbt-sample-project 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.2
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.2
jacek:~/sandbox/stackoverflow/sbt-sample-project
$ mkdir project
jacek:~/sandbox/stackoverflow/sbt-sample-project
$ echo "sbt.version=0.13.1-RC5" > project/build.properties
jacek:~/sandbox/stackoverflow/sbt-sample-project
$ sbt about
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Loading project definition from /Users/jacek/sandbox/stackoverflow/sbt-sample-project/project
[info] Updating {file:/Users/jacek/sandbox/stackoverflow/sbt-sample-project/project/}sbt-sample-project-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to sbt-sample-project (in build file:/Users/jacek/sandbox/stackoverflow/sbt-sample-project/)
[info] This is sbt 0.13.1-RC5
[info] The current project is {file:/Users/jacek/sandbox/stackoverflow/sbt-sample-project/}sbt-sample-project 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3
Related
I have downloaded sbt and to resolve the proxy maven repository errors, I have created repositories files with my-maven-proxy-releases: under ~/.sbt
When I do a sbt about, I get the below details:
"~\.sbt\preloaded\org.scala-sbt\sbt\"1.0.4"\jars\sbt.jar"
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[warn] No sbt.version set in project/build.properties, base directory: C:\
[info] Set current project to root (in build file:/C:/)
[info] This is sbt 1.0.4
[info] The current project is {file:/C:/}root 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
Now, I wanted to import a project in eclipse and I googled. This is the details I found.
1. ~/.sbt/<sbt-version>/plugins/plugins.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
sbteclipse
2. ~/.sbt/<sbt-version>/plugins/build.sbt
for scala versions and dependencies.
But I am confused on where to create the build.sbt and plugins.sbt as my folder structure is like this:
~/.sbt/1.0
~/.sbt/1.3
and I do not see ~/.sbt/1.0.4 which is displayed in sbt about.
Please guide if my understanding wrong.
First, you need to understand sbt project structure and the difference between project-local and global plugins.
As you would usually use eclipse plugin globally you should put it in
~/.sbt/<sbt-version>/plugins/plugins.sbt
(as you wrote correctly), where <sbt-version> is
0.13 for any sbt 0.13.*
1.0 for any sbt 1.*.* (this may seem unintuitive, but it's okay)
I guess, ~/.sbt/1.3 is just a typo and is meant to be ~/.sbt/0.13.
Also you normally don't put anything in ~/.sbt/<sbt-version>/plugins/build.sbt. If you need to have some global settings (including those for the global plugins), you should put them in
~/.sbt/<sbt-version>/global.sbt
Read about global settings here.
With non-global plugins and settings it's all the same minus the ~/.sbt/<sbt-version>/ part:
use <your-project>/plugins/plugins.sbt for plugins
and <your-project>/build.sbt for project settings
Once I run 'sbt compile' on a 2.3 play project, I can't use 'sbt compile' to compile any Play 2.2.x projects anymore. This is the error when I run sbt command.
[info] Loading project definition from /Users/macbookpro/playproject/project
[error] java.lang.NoClassDefFoundError: play/Play$
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
I just had this same issue. In my case I was using Play 2.4, but it's probably the same cause. I had run activator ui in my project directory accidentally. It created a project/play-fork-run.sbt file which is for activator support, but was preventing sbt from working directly. Deleting that file cleared up the issue and I can now use sbt again.
Try updating play-fork-run.sbt
addSbtPlugin("com.typesafe.play" % "sbt-fork-run-plugin" % "2.3.8")
update to
addSbtPlugin("com.typesafe.play" % "sbt-fork-run-plugin" % "2.4.0")
Then project will be able to build.
That's interesting issue since it works for me (TM) on Mac OS X 10.9.3 with Java 7.
I downloaded the versions of Play - the latest 2.3.1 and the latest in 2.2.x stream - 2.2.3. With these two versions I've used activator (2.3.1) to create the web application and play for 2.2.3. Both worked well.
When I executed sbt compile in 2.3.1 and then 2.2.3, both commands worked fine, too. It took me some time to have all the dependencies downloaded, but at the end the results were as follows:
jacek:~/sandbox/play231-app
$ sbt compile
[info] Loading project definition from /Users/jacek/sandbox/play231-app/project
[info] Updating {file:/Users/jacek/sandbox/play231-app/project/}play231-app-build...
...
[info] Done updating.
[info] Compiling 5 Scala sources and 1 Java source to /Users/jacek/sandbox/play231-app/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.1. Compiling...
[info] Compilation completed in 14.895 s
[success] Total time: 200 s, completed Jun 25, 2014 1:00:18 PM
And for 2.2.3:
jacek:~/sandbox/play223-app
$ sbt compile
[info] Loading project definition from /Users/jacek/sandbox/play223-app/project
[info] Set current project to play223-app (in build file:/Users/jacek/sandbox/play223-app/)
[info] Updating {file:/Users/jacek/sandbox/play223-app/}play223-app...
...
[info] Done updating.
[info] Compiling 5 Scala sources and 1 Java source to /Users/jacek/sandbox/play223-app/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.3. Compiling...
[info] Compilation completed in 19.626 s
[success] Total time: 45 s, completed Jun 25, 2014 3:15:34 PM
I'm using sbt 0.13.5 installed using homebrew.
$ sbt --version
sbt launcher version 0.13.5
$ java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
Play 2.3 app is supposed to be built using activator, to ensure proper sbt configuration. Best
I had the same issue. Make sure that you are using the java-8 version.
I was using java-7, changing to java-8 fixed my problem.
I created a multi-project build in sbt. Here's build.sbt in the main directory:
lazy val root = project in file(".") aggregate(data, reco, result)
lazy val data = project dependsOn(common)
lazy val reco = project
lazy val result = project dependsOn(common)
lazy val common = project
When I use package or one-jar command, the classes and resources in common project are not packaged into data or result jars. So when I run the generated jar by
java -jar data_2.10-1.0-onejar.jar
it leads to NoClassDefFoundError as a consequence.
So could anyone help me deal with such problem? Thanks in advance.
Your dependent projects are not exporting Jars (producing classes only). Put the following line in the build.sbt of all dependent projects (including your current project too, if necessary):
exportJars := true
That should fix it.
I might be misunderstanding your issue...please pardon me if I have.
From Classpath dependencies:
A project may depend on code in another project. This is done by
adding a dependsOn method call.
and later (in the same doc):
Now code in core can use classes from util. This also creates an
ordering between the projects when compiling them; util must be
updated and compiled before core can be compiled.
and then in Per-configuration classpath dependencies:
foo dependsOn(bar) means that the compile configuration in foo depends
on the compile configuration in bar.
We may also need to see what package is all about:
> help package
Produces the main artifact, such as a binary jar. This is typically an alias for the task that actually does the packaging.
or even inspect it to see what dependencies it has:
> inspect package
[info] Task: java.io.File
[info] Description:
[info] Produces the main artifact, such as a binary jar. This is typically an alias for the task that actually does the packaging.
[info] Provided by:
[info] {file:/C:/dev/sandbox/0.13.2/}root-0-13-2/compile:package
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:565
[info] Dependencies:
[info] compile:packageBin
[info] Delegates:
[info] compile:package
[info] *:package
[info] {.}/compile:package
[info] {.}/*:package
[info] */compile:package
[info] */*:package
[info] Related:
[info] jacoco:package
[info] test:package
With all that said, package doesn't package other project's artifacts - you need the sbt-assembly plugin instead (as you're crossing the boundaries of a single project and most if not all tasks in sbt are single-project only).
Why are the plugins defined in ~/.sbt/0.13/plugins/build.sbt not included in sbt tasks -V list?
jacek:~/oss/scalania
$ sbt about
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/scalania/project
[info] Set current project to scalania (in build file:/Users/jacek/oss/scalania/)
[info] This is sbt 0.13.0
[info] The current project is {file:/Users/jacek/oss/scalania/}scalania 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info] Available Plugins: com.timushev.sbt.updates.UpdatesPlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, de.johoop.jacoco4sbt.JacocoPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin, com.typesafe.sbt.SbtScalariform, org.scalastyle.sbt.ScalastylePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.2
jacek:~/oss/scalania
$ sbt 'tasks -V idea'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/scalania/project
[info] Set current project to scalania (in build file:/Users/jacek/oss/scalania/)
No matches for regular expression 'idea'.
jacek:~/oss/scalania
$ sbt 'tasks -V' | grep -i idea
The gen-idea task of the sbt-idea plugin works perfectly fine.
jacek:~/oss/scalania
$ sbt gen-idea
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/scalania/project
[info] Set current project to scalania (in build file:/Users/jacek/oss/scalania/)
[info] Creating IDEA module for project 'scalania' ...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Creating IDEA module for project 'answers' ...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Creating IDEA module for project 'exercises' ...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Excluding folder target
[info] Created /Users/jacek/oss/scalania/.idea/IdeaProject.iml
[info] Created /Users/jacek/oss/scalania/.idea
[info] Excluding folder /Users/jacek/oss/scalania/target
[info] Created /Users/jacek/oss/scalania/.idea_modules/scalania.iml
[info] Excluding folder /Users/jacek/oss/scalania/answers/target
[info] Created /Users/jacek/oss/scalania/.idea_modules/answers.iml
[info] Excluding folder /Users/jacek/oss/scalania/exercises/target
[info] Created /Users/jacek/oss/scalania/.idea_modules/exercises.iml
[info] Created /Users/jacek/oss/scalania/.idea_modules/scalania-build.iml
[info] Created /Users/jacek/oss/scalania/.idea_modules/exercises-build.iml
gen-idea is a command, not a task. You should see it in the output of help idea.
How do I check which version of SBT I'm running?
I have the Bash file set up that uses sbt-launch.jar, and it works, but
sbt version
only shows the "project version" (0.1) and
sbt --version
does nothing.
sbt --version
It now works as of version 1.3.3+ (credit to #ElectronWill).
You may also want to use sbt about that (copying Mark Harrah's comment):
The about command was added recently to try to succinctly print the
most relevant information, including the sbt version.
Type "sbt about" and then Enter to get the SBT version:
Running the command, "sbt sbt-version" will simply output your current directory and the version number.
$ sbt sbt-version
[info] Set current project to spark (in build file:/home/morgan/code/spark/)
[info] 0.13.8
In SBT 0.13 and above, you can use the sbtVersion task (as pointed out by #steffen) or about command (as pointed out by #mark-harrah)
There's a difference how the sbtVersion task works in and outside a SBT project. When in a SBT project, sbtVersion displays the version of SBT used by the project and its subprojects.
$ sbt sbtVersion
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Loading project definition from /Users/jacek/oss/scalania/project
[info] Set current project to scalania (in build file:/Users/jacek/oss/scalania/)
[info] exercises/*:sbtVersion
[info] 0.13.1-RC5
[info] scalania/*:sbtVersion
[info] 0.13.1-RC5
It's set in project/build.properties:
jacek:~/oss/scalania
$ cat project/build.properties
sbt.version=0.13.1-RC5
The same task executed outside a SBT project shows the current version of the executable itself.
jacek:~
$ sbt sbtVersion
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to jacek (in build file:/Users/jacek/)
[info] 0.13.0
When you're outside, the about command seems to be a better fit as it shows the sbt version as well as Scala's and available plugins.
jacek:~
$ sbt about
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to jacek (in build file:/Users/jacek/)
[info] This is sbt 0.13.0
[info] The current project is {file:/Users/jacek/}jacek 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.2
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.2
You may want to run 'help about' to read its documentation:
jacek:~
$ sbt 'help about'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to jacek (in build file:/Users/jacek/)
Displays basic information about sbt and the build.
For the sbtVersion setting, the inspect command can help.
$ sbt 'inspect sbtVersion'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to jacek (in build file:/Users/jacek/)
[info] Setting: java.lang.String = 0.13.0
[info] Description:
[info] Provides the version of sbt. This setting should be not be modified.
[info] Provided by:
[info] */*:sbtVersion
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:67
[info] Delegates:
[info] *:sbtVersion
[info] {.}/*:sbtVersion
[info] */*:sbtVersion
[info] Related:
[info] */*:sbtVersion
The version setting that people seem to expect to inspect to know the SBT version is to set The version/revision of the current module.
$ sbt 'inspect version'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to jacek (in build file:/Users/jacek/)
[info] Setting: java.lang.String = 0.1-SNAPSHOT
[info] Description:
[info] The version/revision of the current module.
[info] Provided by:
[info] */*:version
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:102
[info] Reverse dependencies:
[info] *:projectId
[info] *:isSnapshot
[info] Delegates:
[info] *:version
[info] {.}/*:version
[info] */*:version
[info] Related:
[info] */*:version
When used in a SBT project the tasks/settings may show different outputs.
You can use sbt about
Example:
C:\Users\smala>sbt about
[info] Set current project to smala (in build file:/C:/Users/smala/)
[info] This is sbt 0.13.6
[info] The current project is {file:/C:/Users/smala/}smala 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.4
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4"
Recent versions of SBT finally support a standard --version flag!
$ sbt --version
sbt version in this project: 1.6.2
sbt script version: 1.6.2
(tested with 1.6+, but it seems that it has existed since at least 1.3.3)
From within the sbt shell
sbt:venkat> about
[info] This is sbt 1.3.3
...
What happens when you run sbt from the command line might have changed a bit over the 9 years since the question was originally posted.
Today, you will always be interacting with at least two "versions":
the launcher script (e.g. /usr/local/bin/sbt) version.[1] Check with sbt --script-version.
the default SBT version (=sbt-launcher JAR version), decided primarily by the project SBT version (in project/build.properties), secondarily by the launcher script itself. Check with sbt --script-version (or sbtVersion in the SBT shell)
Fortunately, in most day-to-day scenarios, the project SBT version is the only one that you need to be aware of.
1
It used to be just java -jar sbt-launcher.jar, then there was/is sbt-extras/sbt (aka "rebel cut"), then there was the "official" sbt script but in a separate github project called sbt-launcher-packaging (now archived). Today, the default script sits in the root folder of the sbt/sbt GH project and is generally the only version you need to worry about.
Run the SBT console and then type sbtVersion to check the SBT version, and scalaVersion for the Scala runtime version.
Doing sbt sbt-version led to some error as
[error] Not a valid command: sbt-version (similar: writeSbtVersion, session)
[error] Not a valid project ID: sbt-version
[error] Expected ':'
[error] Not a valid key: sbt-version (similar: sbtVersion, version, sbtBinaryVersion)
[error] sbt-version
[error] ^
As you can see the hint similar: sbtVersion, version, sbtBinaryVersion, all of them work but the correct one is generated by sbt sbtVersion