解释定义libraryDependencies的表达式之间的区别

时间:2015-04-07 17:53:03

标签: sbt

我无法理解以下表达式之间的区别。表达式减少了 - 现实世界的情况下有更多的设置分布在单独的对象中。

  1. 直接指定为序列

    Seq(libraryDependencies +=
      "org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile")
    
  2. 包裹在inConfig

    inConfig(Compile)(libraryDependencies +=
      "org.openjdk.jmh" % "jmh-core" % "1.6.2" % "compile")
    
  3. 在这两种情况下,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的依赖仅在第一种情况下显示。因此,由于无法解析的类,正常的编译器运行失败。

    请解释或指出两种情况之间的逻辑差异。

1 个答案:

答案 0 :(得分:1)

TLDR:在声明% "compile"时使用Compile libraryDependencies


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表明您仅在jmh-core的{​​{1}}轴中添加了Compile

  1. libraryDependencies

    show libraryDependencies
  2. [info] List(org.scala-lang:scala-library:2.10.4, org.openjdk.jmh:jmh-core:1.6.2:compile)

    show libraryDependencies
  3. 然后导致[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

相关问题