Abstract: This article introduce how to use the single (
%) and double (
%%) per cent sign in
As we know, in the sbt dependency description, there are two type symbols:
- single per cent sign
- double per cent sign
The latest Play framework official document Managing library dependencies give a detail description of how to add the dependency to the sbt build description file.
If you use
groupID %% artifactID % revision rather than
groupID % artifactID % revision (the difference is the double
%% after the
groupID), sbt will add your project’s Scala version to the artifact name. This is just a shortcut. You could write this without the
libraryDependencies += "org.scala-stm" % "scala-stm_2.11" % "0.8"
scalaVersion for your build is
2.11.1, the following is identical (note the double
libraryDependencies += "org.scala-stm" %% "scala-stm" % "0.8"
The idea is that many dependencies are compiled for multiple Scala versions, and you’d like to get the one that matches your project to ensure binary compatibility.
One important thing, most of the dependency from the maven central repository, you should use the single
%, because they do not care about the Scala version. If you use the double
%%, the sbt will expand it with Scala version, and it will not match the maven.
, you should use this:
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.26"
if you use the double per cent sign, the final dependency will not be found because it will be changed to
If there is Scala column for the dependency in maven central repository which means that you can use double per cent sign, but you should still make sure that the Scala version you are using occurs in the list of the dependency.
For example, if you use
Akka-actor version of 2.5.18, you can only use the scala 2.11 and 2.12