Scala Incremental compile fails with java.lang.NoClassDefFoundError: xsbti/CompileFailed

Using

tasks.withType(ScalaCompile) {

scalaCompileOptions.useAnt = false

}

In gradle 1.10, 1.11, and the latest 2.0 nightly build I get this error

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myProject:compileScala'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
...
Caused by: java.lang.NoClassDefFoundError: xsbti/CompileFailed
        at org.gradle.api.internal.tasks.scala.jdk6.ZincScalaCompiler.execute(ZincScalaCompiler.java:50)
        at org.gradle.api.internal.tasks.scala.jdk6.ZincScalaCompiler.execute(ZincScalaCompiler.java:43)
        at org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonServer.execute(CompilerDaemonServer.java:53)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)

Do I need to explicitly import xsbti lib?

scala -version: Scala code runner version 2.10.3 – Copyright 2002-2013, LAMP/EPFL

java -version:

java version “1.7.0_21” Java™ SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot™ 64-Bit Server VM (build 23.21-b01, mixed mode)

You don’t have to import xsbti. Can you show the Scala related parts of your build script, e.g. Scala dependency declaration and such?

I have a multi project build.

Here is the scala related bits in my parent script:

subprojects {
    tasks.withType(ScalaCompile) {
        scalaCompileOptions.useAnt = false
        scalaCompileOptions.additionalParameters = ['-feature']
    }
}

Subproject build script:

apply plugin: 'java'
apply plugin: 'scala'
    dependencies {
   ...
    compile
 'org.scala-lang:scala-library:2.10.3'
    compile
 'org.scala-lang:scala-reflect:2.10.3'
    compile
 'org.springframework.scala:spring-scala:1.0.0.M2'
}

Do you get the same error when executing the ‘scala/zinc’ sample in the full Gradle distribution (after introducing a compile error and perhaps upgrading to Scala 2.10.3)? If I’m not mistaken, we had to upgrade Zinc to work with Scala 2.10.3, but this should already be in the latest 2.0 nightly build (and the upcoming 1.12).

Peter,

The example works just fine. I did some digging and tracked it down. In my subprojects configuration I have.

configurations.all {
    transitive = false
}

Once I put this in the example, I got the same error. What’s the best way to set transitive off for everything but the zinc lib? Or is there another preferred solution?

Thanks!

Only do it for configurations where you need it, e.g. ‘compile’ and ‘runtime’. Or set dependencies to non-transitive rather than configurations. Or set the ‘zinc’ configuration back to ‘transitive = true’.

Thanks Peter, I ended up with doing this in my subprojects closure:

configurations.all {
    transitive = false
}
project.plugins.withType(ScalaPlugin) {
    configurations.zinc.transitive=true
}

Looks good. Alternatively, this should also work:

configurations.matching { it.name != "zinc" }.all {
    transitive = false
}

Note that there are other configurations where you wouldn’t want to turn off transitivity, e.g. ‘checkstyle’, ‘findbugs’, or configurations added by third-party plugins. That’s why it’s more robust to selectively turn off transitivity.