taskKey
我有以下习惯built.sbt
:
(这是我第一次尝试定义自定义 SBT 任务,所以要小心愚蠢)
lazy val makeDeployJar = taskKey[java.io.File](
"Runs 'package', collects all the sub-project JARs in the lib folder of the root project, and runs 'one-jar'")
makeDeployJar := {
val jars = List(
(Keys.`package` in Compile in root).value,
(Keys.`package` in Compile in common).value
(Keys.`package` in Compile in core).value,
(Keys.`package` in Compile in analysisProj).value,
(Keys.`package` in Compile in ui).value
)
// looks like OneJar operates on JARs in the lib folder only, so need to collect all JARs
// and temporarily copy them to lib and delete them later:
val libDir = (baseDirectory in root).value / "lib"
val libPaths = jars.map(libDir / _.getName)
IO.copy(jars zip libPaths)
val oneJarOutput = oneJar.value
IO.delete(libPaths)
// move the resulting JAR to a more human friendly location
val finalPath = (baseDirectory in root).value / "profile.jar"
IO.copyFile(oneJarOutput, finalPath)
// this is the tedious SBT way of logging
streams.value.log.info(finalPath.toString)
// return the resulting JAR path for completeness' sake
finalPath
}
虽然很复杂,但它运行良好并产生了我想要的结果。
但是,当我将以下内容添加到我的built.sbt
:
artifactName in ThisBuild := {
(_: ScalaVersion, module: ModuleID, artifact: Artifact) =>
artifact.name + "-" + module.revision + "." + artifact.extension
}
每当我运行makeDeployJar
任务时,它在输出后无限期挂起:
...
[info] Compiling 16 Scala sources and 3 Java sources to /myproj/ui/target/scala-2.10/classes...
[info] Packaging /myproj/target/scala-2.10/myproj-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[info] Packaging /myproj/target/scala-2.10/myproj-0.1-SNAPSHOT.jar ...
SBT 是一个复杂的野兽,而我是 SBT 的新手——我做错了什么,还是这是 SBT 中的一个错误?