183

I'm new to Play! Framework 2.1 (java version) and have no experience with scala. I don't understand what are and what does % and %% mean in Build.scala. I googled about them but couldn't find their meaning.

In my Build.scala file I have:

"org.hibernate" % "hibernate-entitymanager" % "4.1.0.Final",
"com.typesafe" %% "play-plugins-mailer" % "2.1"

Why the first line uses a single % symbol and the second one uses two percent symbols %%? What are they for?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Franco
  • 11,845
  • 7
  • 27
  • 33

2 Answers2

206

From the official documentation:

http://www.playframework.com/documentation/2.1.1/SBTDependencies

Getting the right Scala version with %%

If you use groupID %% artifactID % revision instead of 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 %%:

val appDependencies = Seq(
  "org.scala-tools" % "scala-stm_2.9.1" % "0.3"
)

Assuming the scalaVersion for your build is 2.9.1, the following is identical:

val appDependencies = Seq(
  "org.scala-tools" %% "scala-stm" % "0.3"
)

As you can see above, if you use %%, you don't have to specify the version.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Mingyu
  • 31,751
  • 14
  • 55
  • 60
  • 3
    "Your project's Scala version" means the value of the SettingKey `scalaVersion`. – Gordon Gustafson Mar 13 '16 at 16:54
  • 4
    don't think raising a separate SO question is required for my additional question: when would I _not_ want to use %% ? To me it looks like it's 'better' and should be used always.... – Peter Perháč Aug 10 '16 at 18:33
  • 10
    @PeterPerháč you cannot use `%%` with artifacts that don't contain a Scala version (such as pure Java libraries). – Toxaris Oct 27 '16 at 23:15
34

This is part of SBT which play uses as a build tool. Specifically this is an import statement.

The percent symbol % is a actually a method used to build dependencies. The double percent sign %% injects the current Scala version - this allows you to get the correct library for the version of scala you are running. This is to avoid having to change your build file when you update Scala.

More information here

Yves M.
  • 29,855
  • 23
  • 108
  • 144
Boris the Spider
  • 59,842
  • 6
  • 106
  • 166