在sbt libraryDependencies里面定义scalatest的时候,为什么大家都用"test"配置?

When defining scalatest within sbt libraryDependencies, why does everyone use the "test" configuration?

尝试在这里学习 Scala 和 sbt 的初学者。此外,很少有 Maven 经验。所以,可能是个愚蠢的问题。

在 build.sbt 中定义 libraryDependencies 时,我经常看到这样的例子:

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.6" % "test"

这遵循以下格式:

libraryDependencies += groupID % artifactID % version % configuration

在这种情况下,我们为什么要对 configuration 字段使用 test?除了网络上的 copy/pasting 个例子,我怎么知道呢?

任何见解都可以帮助我更好地理解如何在我的项目中一般指定库依赖项。此外,我将不胜感激对 material 的任何引用,我可以用来更深入地研究该主题。

您可以在以下链接中找到有用的链接:

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.