SBT custom task hangs

159 Views Asked by At

I have the following custom taskKey in my built.sbt:

(it's my first attempt at defining a custom SBT task, so beware of stupidities)

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
}

Convoluted though it is, it runs fine and produces the result I'm after.

However, when I add the following to my built.sbt:

artifactName in ThisBuild := {
  (_: ScalaVersion, module: ModuleID, artifact: Artifact) =>
  artifact.name + "-" + module.revision + "." + artifact.extension
}

whenever I run the makeDeployJar task, it hangs indefinitely after outputing:

...
[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 is a complicated beast, and I'm new to SBT—am I doing something wrong, or is this a bug in SBT?

0

There are 0 best solutions below