How to depend on other tasks and make your code in SBT 0.10?

I want to define a task that calls compilation and packageBin tasks, and then does its stuff. How should I do it? Currently, this only does the second part and skips compilation and packageBin tasks.

lazy val dist = TaskKey[Unit](
  "dist", "Creates a project distribution in dist/ folder."
)
def distTask = {
  dist <<= dist.dependsOn(compile, packageBin)
  dist <<= (update, crossTarget).map { case (updateReport, out) =>
    updateReport.allFiles.foreach { srcPath =>
      val destPath = out / "lib" / srcPath.getName
      IO.copyFile(srcPath, destPath, preserveLastModified=true)
    }
  }
}
+5
source share
1 answer

<<=is a TaskKey method that returns a value. It does not update the mutable state anywhere, so in the code example, the result of the first call is discarded. To fix this, declare packageBin as input, but ignore the resulting value. Note that packageBin is compilation dependent, so there is no need for compilation.

dist <<= (update, crossTarget, packageBin in Compile) map { (updateReport, out, _) =>

, UpdateReport , . , . , , .

ModuleID, , lib_managed, retrieveManaged := true. .

updateReport.matching(configurationFilter(Runtime.name)).foreach...

sbt.UpdateReport sbt.RichUpdateReport API- .

, dependencyClasspath. :

dist <<= (crossTarget, packageBin in Compile, dependencyClasspath in Runtime) map { (out, _, cp) =>

Seq[File] cp.files.

+3

All Articles