Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the % and %% operators do when setting up SBT dependencies?

Tags:

scala

sbt

lift

In Lift Web Framework, dependencies for Simple Build Tool (SBT) are specified in LiftProject.scala. That file includes this code:

  override def libraryDependencies = Set(
    "net.liftweb"             %% "lift-webkit"   % liftVersion % "compile->default",
    "net.liftweb"             %% "lift-mapper"   % liftVersion % "compile->default",
    "org.mortbay.jetty"       % "jetty"          % "6.1.22"    % "test->default",
    "junit"                   % "junit"          % "4.5"       % "test->default",
    "org.scala-tools.testing" %% "specs"         % "1.6.6"     % "test->default",
    "org.scala-lang"          % "scala-compiler" % "2.8.1"     % "test->default",
    "org.apache.tomcat"       % "tomcat-juli"    % "7.0.0"     % "test->default",
    "com.h2database"          % "h2"             % "1.2.138"
  ) ++ super.libraryDependencies

What do the % and %% operators do here? If I paste this code into the scala interpreter, it errors out, and neither % nor %% is defined for String or RichString. What's going on here?

like image 521
Jake Becker Avatar asked May 15 '11 22:05

Jake Becker


1 Answers

The difference between these functions is that %% considers Scala version when SBT resolve dependency, so for example net/liftweb/lift-webkit_2.8.1/2.3/lift-webkit_2.8.1-2.3.jar will be downloaded from repo.

Regarding compile error - these methods should be called when some implicit methods defined in SBT class hierarchy that make actual conversion are in scope.

Best regards, Vladimir

like image 119
lester Avatar answered Oct 19 '22 07:10

lester