解释定义 libraryDependencies 的表达式之间的区别
Explaining the Difference between Expressions defining libraryDependencies
我无法理解以下表达式之间的区别。表达式减少了——现实世界的情况有更多的设置分布在单独的对象中。
直接指定为序列
Seq(libraryDependencies +=
"org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile")
包裹在inConfig
inConfig(Compile)(libraryDependencies +=
"org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile")
在这两种情况下 show compile:libraryDependencies
显示相同
[info] List(org.scala-lang:scala-library:2.10.4, org.openjdk.jmh:jmh-core:1.6.2:compile)
但对于 show compile:managedClasspath
对 JMH 的依赖仅在第一种情况下显示。结果,由于无法解析 类.
,普通编译器 运行 失败
请解释或指出两种情况之间的逻辑差异。
TLDR: 在声明 libraryDependencies
[=36= 时使用 % "compile"
而不是 Compile
]
您看到的是 sbt
如何尝试使用 Ivy 的模块配置(例如 compile
)作为其设置范围之一的差距,可能是错误。
供参考:
问题在于,目前,您可以在值级别声明配置:
"org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile"
和关键级别:
inConfig(Compile)(libraryDependencies += xyz)
或者:
libraryDependencies in Compile += xyz
正如您在两个示例中所说的那样,show compile:libraryDependencies
显示了相同的序列,但是 show libraryDependencies
表明您只在 [=18= 的 Compile
轴中添加了 jmh-core
]:
show libraryDependencies
[info] List(org.scala-lang:scala-library:2.10.4, org.openjdk.jmh:jmh-core:1.6.2:compile)
show libraryDependencies
[info] List(org.scala-lang:scala-library:2.10.4)
这就导致了为什么 show compile:managedClasspath
不同。
看看 inspect actual compile:managedClasspath
的输出:
[info] Task: scala.collection.Seq[sbt.Attributed[java.io.File]]
[info] Description:
[info] The classpath consisting of external, managed library dependencies.
[info] Provided by:
[info] {file:/Users/dnw/Desktop/t-2015-04-08.0540/}t-2015-04-08-0540/compile:managedClasspath
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:991
[info] Dependencies:
[info] *:update
[info] */*:classpathTypes
[info] compile:classpathConfiguration
[info] compile:managedClasspath::streams
[info] Reverse dependencies:
[info] compile:externalDependencyClasspath
[info] Delegates:
[info] compile:managedClasspath
[info] *:managedClasspath
[info] {.}/compile:managedClasspath
[info] {.}/*:managedClasspath
[info] */compile:managedClasspath
[info] */*:managedClasspath
[info] Related:
[info] test:managedClasspath
[info] runtime:managedClasspath
需要注意的是它对 *:update
的依赖性,它不在 compile
范围内。从那里它最终导致 *:libraryDependencies
在你的第二个例子中不包括 jmh-core
.
我无法理解以下表达式之间的区别。表达式减少了——现实世界的情况有更多的设置分布在单独的对象中。
直接指定为序列
Seq(libraryDependencies += "org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile")
包裹在
inConfig
inConfig(Compile)(libraryDependencies += "org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile")
在这两种情况下 show compile:libraryDependencies
显示相同
[info] List(org.scala-lang:scala-library:2.10.4, org.openjdk.jmh:jmh-core:1.6.2:compile)
但对于 show compile:managedClasspath
对 JMH 的依赖仅在第一种情况下显示。结果,由于无法解析 类.
请解释或指出两种情况之间的逻辑差异。
TLDR: 在声明 libraryDependencies
[=36= 时使用 % "compile"
而不是 Compile
]
您看到的是 sbt
如何尝试使用 Ivy 的模块配置(例如 compile
)作为其设置范围之一的差距,可能是错误。
供参考:
问题在于,目前,您可以在值级别声明配置:
"org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile"
和关键级别:
inConfig(Compile)(libraryDependencies += xyz)
或者:
libraryDependencies in Compile += xyz
正如您在两个示例中所说的那样,show compile:libraryDependencies
显示了相同的序列,但是 show libraryDependencies
表明您只在 [=18= 的 Compile
轴中添加了 jmh-core
]:
show libraryDependencies
[info] List(org.scala-lang:scala-library:2.10.4, org.openjdk.jmh:jmh-core:1.6.2:compile)
show libraryDependencies
[info] List(org.scala-lang:scala-library:2.10.4)
这就导致了为什么 show compile:managedClasspath
不同。
看看 inspect actual compile:managedClasspath
的输出:
[info] Task: scala.collection.Seq[sbt.Attributed[java.io.File]]
[info] Description:
[info] The classpath consisting of external, managed library dependencies.
[info] Provided by:
[info] {file:/Users/dnw/Desktop/t-2015-04-08.0540/}t-2015-04-08-0540/compile:managedClasspath
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:991
[info] Dependencies:
[info] *:update
[info] */*:classpathTypes
[info] compile:classpathConfiguration
[info] compile:managedClasspath::streams
[info] Reverse dependencies:
[info] compile:externalDependencyClasspath
[info] Delegates:
[info] compile:managedClasspath
[info] *:managedClasspath
[info] {.}/compile:managedClasspath
[info] {.}/*:managedClasspath
[info] */compile:managedClasspath
[info] */*:managedClasspath
[info] Related:
[info] test:managedClasspath
[info] runtime:managedClasspath
需要注意的是它对 *:update
的依赖性,它不在 compile
范围内。从那里它最终导致 *:libraryDependencies
在你的第二个例子中不包括 jmh-core
.