beginner trying to learn Scala and sbt here. Also, very little Maven experience. So, possibly a stupid question.
When defining libraryDependencies within build.sbt, often I see examples such as:
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.6" % "test"
This follows the format:
libraryDependencies += groupID % artifactID % version % configuration
In this scenario, why are we using test
for the configuration
field? How would I know that other than copy/pasting examples from the web?
Any insight could help a lot for me better understand how to specify library dependencies in general within my projects. Also, any references to material that I could use to dive deeper into the subject would be appreciated.
You can find useful the following links:
http://www.scala-sbt.org/0.13/docs/Library-Management.html#ivy-configurations
You put a dependency in a configuration by selecting one or more of its configurations to map to one or more of your project’s configurations. The most common case is to have one of your configurations A use a dependency’s configuration B. The mapping for this looks like "A->B". To apply this mapping to a dependency, add it to the end of your dependency definition:
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.3" % "test->compile"
This says that your project’s "test" configuration uses ScalaTest’s "compile" configuration. Most projects published to Maven repositories will use the "compile" configuration.
A configuration without a mapping (no "->") is mapped to "default" or "compile". The -> is only needed when mapping to a different configuration than those.
https://ant.apache.org/ivy/history/2.3.0/tutorial/conf.html
build->api : here we tell Ivy that our build configuration depends on the api configuration of the dependency
noexternaljar->homemade-impl : here we tell Ivy that our noexternaljar configuration depends on the homemade-impl configuration of the dependency.
withexternaljar->cc-impl : here we tell Ivy that our withexternaljar configuration depends on the cc-impl configuration of the dependency
http://www.scala-sbt.org/0.13/docs/Testing.html
lazy val scalacheck = "org.scalacheck" %% "scalacheck" % "1.13.4"
libraryDependencies += scalacheck % Test
Test is the configuration and means that ScalaCheck will only be on the test classpath and it isn’t needed by the main sources. This is generally good practice for libraries because your users don’t typically need your test dependencies to use your library.