356

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jpswain
  • 14,642
  • 8
  • 58
  • 63

10 Answers10

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Steffen
  • 8,033
  • 1
  • 28
  • 34
36

Type "sbt about" and then Enter to get the SBT version:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prasad
  • 616
  • 7
  • 11
30

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
Morgan Kenyon
  • 3,072
  • 1
  • 26
  • 38
  • 16
    Starting with sbt 1.0 you even *have* to use `sbt sbtVersion` (camelCase) as support for [hyphen-separated names has been dropped](http://www.scala-sbt.org/1.x/docs/sbt-1.0-Release-Notes.html). – sschuberth Sep 04 '17 at 19:09
16

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.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
  • 1
    Perhaps you are using a custom sbt launcher, such as sbt-extras, that overrides the meaning of `sbt-version` one the command line. Otherwise, I don't know of a difference between `sbt-version` at the command line and at the prompt. It should be the same `sbtVersion` setting in both cases. – Mark Harrah Dec 02 '13 at 21:59
  • is there any way to set the different sbt versions for the different subprojects? – Incerteza Dec 29 '13 at 13:27
  • 1
    http://stackoverflow.com/questions/20825539/specify-the-version-of-sbt-for-a-subproject – Incerteza Dec 29 '13 at 13:41
  • Why does `sbt sbtVersion` run outside a project take 9 seconds to run? Python, node and ruby all take under a second, as do awk, sed, minibloom and a bunch of other command line tools. gcc takes one whole second, which is super-slow. But 9 seconds takes the cherry. What is sbt doing in that time? – Max Murphy Mar 18 '18 at 10:20
  • @MaxMurphy JVM initialization is among the slowest things I think. – Jacek Laskowski Mar 18 '18 at 12:53
10

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"
Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
Sandeep M
  • 248
  • 3
  • 6
  • 1
    For others who are seeking the answer to this question, THIS is the answer. Cannot understand why the erroneous answer above was accepted... by digging through the disucssion, one can find this answer... but... – TheGeeko61 Mar 31 '18 at 04:35
5

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)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ElectronWill
  • 754
  • 9
  • 17
3

From within the sbt shell

sbt:venkat> about
[info] This is sbt 1.3.3
...
Venkat Kotra
  • 10,413
  • 3
  • 49
  • 53
2

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.

conny
  • 9,973
  • 6
  • 38
  • 47
1

Run the SBT console and then type sbtVersion to check the SBT version, and scalaVersion for the Scala runtime version.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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

Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97