简体   繁体   中英

Adding an SBT plugin which does not specify an SBT version in its URL

Specs2 does not define the SBT version in its URL: https://oss.sonatype.org/content/repositories/releases/org/specs2/specs2_2.9.2/1.12.3/

This is causing problems for SBT when trying to resolve it...

[warn] ==== sonatype-snapshots: tried
[warn]   https://oss.sonatype.org/content/repositories/snapshots/org/specs2/specs2_2.9.2_0.12/1.12.3/specs2-1.12.3.pom
[warn] ==== sonatype-releases: tried
[warn]   https://oss.sonatype.org/content/repositories/releases/org/specs2/specs2_2.9.2_0.12/1.12.3/specs2-1.12.3.pom

How do I get SBT to resolve the correct URL?

specs2 is not a sbt plugin it's a Scala library for writing executable software specifications .

There are two levels of sbt projects. Your own projects (for now call them "apps") and the build project definition itself (call it "the build").

library dependencies

When apps use other libraries during compilation or test, they are called library dependencies (or "deps" for short). These deps are declared in build.sbt (or *.sbt or project/*.scala ) as follows:

libraryDependencies += "org.specs2" %% "specs2" % "2.2" % "test"

By saying %% , artifacts published using sbt automatically appends Scala binary version postfix such as _2.10 on Maven. This is due to the fact that (unlike Java) not all Scala releases are binary compatible with each other. Scala 2.9.1 and 2.9.2 are not compatible, so they both have distinct postfix _2.9.1 and _2.9.2 , but Scala 2.10.x are all compatible among the series so they are given _2.10 .

Unfortunately, however, different versions of Specs2 are required for Scala versions, you might have to do something more like:

libraryDependencies <+= scalaVersion({
  case "2.9.2"                  => "org.specs2" %% "specs2" % "1.12.3" % "test"
  case x if x startsWith "2.10" => "org.specs2" %% "specs2" % "2.2" % "test"
})

For more details check out Getting Started guide.

sbt plugins

There are special type of libraries that the build can depend on to extend its abilities, and they are sbt plugins. These are declared in project/plugins.sbt (or project/*.sbt ) as follows:

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.5")

Since sbt plugins are dependent on sbt version and the Scala version that the build uses, both of those information are encoded somehow into the published artifact path. On Ivy, they are expressed as folder names but on Maven they are expressed as postfix:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM