开发者

What does "str" % "str" mean in SBT?

I came across this code:

impor开发者_运维问答t sbt._ 

class AProject(info: ProjectInfo) extends DefaultProject(info) { 
  val scalaToolsSnapshots = ScalaToolsSnapshots
  val scalatest = "org.scalatest" % "scalatest" %
    "1.0.1-for-scala-2.8.0.RC1-SNAPSHOT"
}

And I'm quite confused as to what scalatest contains, and what the % does.


It declares a dependency. In particular,

val scalatest = "org.scalatest" % "scalatest" % "1.0.1-for-scala-2.8.0.RC1-SNAPSHOT

refers to a dependency which can be found at

http://scala-tools.org/repo-snapshots/org/scalatest/scalatest/1.0.1-for-scala-2.8.0.RC1-SNAPSHOT/

Where everything before org refers to the repository, which is (pre-)defined elsewhere.

It is not easy to find the implicit that enables % on String, but, for the record, it is found on ManagedProject, converting a String into a GroupID. In the same trait there's also another implicit which enables the at method.

At any rate, the implicit will turn the first String into a GroupID, the first % will take a String representing the artifact ID and return a GroupArtifactID, and the second will take a String representing the revision and return a ModuleID, which is what finally gets assigned to scalatest.


If you used Maven this is essentially the same thing but with Scala DSL. % works as a separator:

<dependency>
      <groupId>org.scalatest</groupId>
      <artifactId>scalatest</artifactId>
      <version>1.0.1-for-scala-2.8.0.RC1-SNAPSHOT</version>      
</dependency>

Read more: http://code.google.com/p/simple-build-tool/wiki/LibraryManagement

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜