sbt / sbt-assembly

Deploy über-JARs. Restart processes. (port of codahale/assembly-sbt)
MIT License
1.95k stars 224 forks source link

Overriding assembly task #344

Closed ov7a closed 6 years ago

ov7a commented 6 years ago

I want to run a few checks for assembled jar.

I'm trying to override an assembly task with the following code (using example from https://www.scala-sbt.org/1.0/docs/Howto-Dynamic-Task.html):

assembly in assembly := Def.taskDyn {
  val assembledJar = (assembly in assembly).value
  println("we are in patched assembly")
  Def.task {
    import scala.sys.process._
    val testFilesDir = (resourceDirectory in Test).value / "files"
    testFilesDir.listFiles().foreach { testFile =>
      val exitCode = "some_external_command" !
      if (exitCode != 0) {
        throw new RuntimeException(s"Checking assembled jar failed for $testFile")
      }
    }
    assembledJar
  }
}.value

and this does not work. Jar is assembled, but even the text in println is not printed.

However, if I change assembly to compile - overriding works and the debug line is printed:

compile in Compile := Def.taskDyn {
  println("DYNAMIC 1")
  val old = (compile in Compile).value
 Def.task {
    println("DYNAMIC 2")
    import scala.sys.process._
    val testFilesDir = (resourceDirectory in Test).value / "files"
    testFilesDir.listFiles().foreach { testFile =>
      val exitCode =  "some_external_command" !
      if (exitCode != 0) {
        throw new RuntimeException(s"Task assemblyJarCheck failed for $testFile")
      }
    }
    old
  }
}.value

What I'm doing wrong?

ov7a commented 6 years ago

My bad. Sorry for inconvenience. The trick was that I used assembly in assembly instead of just assembly. In previous versions of sbt Assembly was a Configuration like Compile. But now it is only a task, so assembly in assembly is meaningless.