In a Scala project, you want to make sure you always have the desired version of a managed dependency in SBT, including the latest integration release, milestone release, or other versions.
revision field in the
libraryDependencies setting isn’t limited to specifying a single, fixed version. According to the Apache Ivy documentation, you can specify terms such as
latest.milestone, and other terms.
As one example of this flexibility, rather than specifying version 1.8 of a
foobar module, as shown here:
libraryDependencies += "org.foobar" %% "foobar" % "1.8"
you can request the
latest.integration version like this:
libraryDependencies += "org.foobar" %% "foobar" % "latest.integration"
The module developer will often tell you what versions are available or should be used, and Ivy lets you specify tags to control which version of the module will be downloaded and used. The Ivy “dependency” documentation states that the following tags can be used:
- latest.[any status], such as latest.milestone
- You can end the revision with a + character. This selects the latest subrevision of the dependency module. For instance, if the dependency module exists in revisions 1.0.3, 1.0.7, and 1.1.2, specifying 1.0.+ as your dependency will result in 1.0.7 being selected.
You can use “version ranges,” as shown in the following examples:
[1.0,2.0] matches all versions greater or equal to 1.0 and lower or equal to 2.0 [1.0,2.0[ matches all versions greater or equal to 1.0 and lower than 2.0 ]1.0,2.0] matches all versions greater than 1.0 and lower or equal to 2.0 ]1.0,2.0[ matches all versions greater than 1.0 and lower than 2.0 [1.0,) matches all versions greater or equal to 1.0 ]1.0,) matches all versions greater than 1.0 (,2.0] matches all versions lower or equal to 2.0 (,2.0[ matches all versions lower than 2.0
(These configuration examples are courtesy of the Apache Ivy documentation. See the link in the See Also section for more information.)
To demonstrate a few of these tags, this example shows the
libraryDependencies += "org.scalatest" %% "scalatest" % "latest.milestone" % " "test"
At the time of this writing, it retrieves this file:
This specification demonstrates the
libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.+" % "test"
It currently retrieves this file:
The Scala Cookbook
This tutorial is sponsored by the Scala Cookbook, which I wrote for O’Reilly:
You can find the Scala Cookbook at these locations: