为什么unmanagedJars和libraryDependencies的使用之间存在不一致?

时间:2015-04-13 08:11:49

标签: scala sbt

SBT 0.13.8

我试图弄清楚unmanagedJarslibraryDependencies之间似乎不一致的行为。我尽力在下面的Build.scala文件中总结我的困惑。

import sbt._
import Keys._

object DemoBuild extends Build {
  def findTypesafeConfigJar(baseDir:File) =
    Attributed.blank(baseDir / "extra-jars/config-1.2.1.jar")

  override lazy val settings = super.settings ++ Seq(
    //CONTROL
    //typesafeConfigAsLibraryDependency()
    //ATTEMPT #1
    //typesafeConfigAsUnmanagedJar1()
    //ATTEMPT #2
    //typesafeConfigAsUnmanagedJar2()
  )

  val root = (project in file(".")).settings(
    //ATTEMPT #3
    //typesafeConfigAsUnmanagedJar1()
    //ATTEMPT #4
    //typesafeConfigAsUnmanagedJar2()
  )

  def typesafeConfigAsLibraryDependency() =
    libraryDependencies += "com.typesafe" % "config" % "1.2.1"

  def typesafeConfigAsUnmanagedJar1() =
    unmanagedJars += findTypesafeConfigJar(baseDirectory.value)

  def typesafeConfigAsUnmanagedJar2() =
    unmanagedJars in Compile += findTypesafeConfigJar(baseDirectory.value)
}

尝试#1失败:

[error] Reference to undefined setting: 
[error] 
[error]   {.}/*:unmanagedJars from {.}/*:unmanagedJars (/somewhere/on/filesystem/_root/project/DemoBuild.scala:28)
[error]      Did you mean compile:unmanagedJars ?

尝试#2失败:

[error] Reference to undefined setting: 
[error] 
[error]   {.}/compile:unmanagedJars from {.}/compile:unmanagedJars (/somewhere/on/filesystem/_root/project/DemoBuild.scala:31)
[error]      Did you mean compile:unmanagedJars ?

尝试#3失败:

[error] Reference to undefined setting: 
[error] 
[error]   *:unmanagedJars from *:unmanagedJars (/somewhere/on/filesystem/_root/project/DemoBuild.scala:28)
[error]      Did you mean compile:unmanagedJars ?

尝试#4成功......

我一直在尝试利用SBT教程的Scopes部分中的材料无济于事。我唯一理解的是,将unmanagedJars的范围缩小到根项目的Compile配置会使怪物消失。但是,我不知道为什么会这样。

  1. delegation发生了什么?
  2. 为什么libraryDependencies设置如此根本不同而且更容易使用?
  3. (project in file(".")).settings(...)咒语对我来说太神奇了,有没有“更清洁”的选择?我尝试向unmanagedJars in (RootProject, Compile)块添加不同的内容(沿着override lazy val settings行)但没有任何成功。
  4. 是否有任何 runnable 示例展示沿不同轴的范围(特别是unmanagedJars)?
  5. unmanagedJarsunmanagedClasspath设置之间的区别是什么?
  6. 最后一点,我对使用*.sbt构建定义不感兴趣,因此请保留特定于*.scala构建定义的答案。

0 个答案:

没有答案