SBT 0.13.8
我试图弄清楚unmanagedJars
和libraryDependencies
之间似乎不一致的行为。我尽力在下面的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
配置会使怪物消失。但是,我不知道为什么会这样。
libraryDependencies
设置如此根本不同而且更容易使用?(project in file(".")).settings(...)
咒语对我来说太神奇了,有没有“更清洁”的选择?我尝试向unmanagedJars in (RootProject, Compile)
块添加不同的内容(沿着override lazy val settings
行)但没有任何成功。unmanagedJars
)?unmanagedJars
和unmanagedClasspath
设置之间的区别是什么?最后一点,我对使用*.sbt
构建定义不感兴趣,因此请保留特定于*.scala
构建定义的答案。