Default Scala Compiler Doesn't Work in Gradle 2.12 & Scala 2.11


(Adrian George) #1

While trying to upgrade scala from 2.10 to 2.11 we are seeing compiler problems. Specifically we get:
Which occurs when the compiler version doesn’t match the language version.

Strangely in our multi project build it would work for the first project it saw with scala, but fail for the others. If i deleted the project gradle cache, i could get one more module to compile correctly. Once i deleted my main (user) gradle cache all scala projects started failing in this same way.

I tried running with a --info and got the following:
Started Gradle compiler daemon (0.326 secs) with fork options DaemonForkOptions{minHeapSize=null, maxHeapSize=null, jvmArgs=[], classpath=[/home/adrian/.gradle/caches/modules-2/files-2.1/com.typesafe.zinc/zinc/0.3.7/6c42a48a9f55f74fae9706083c470c7d8cc512ee/zinc-0.3.7.jar, /home/adrian/.gradle/caches/modules-2/files-2.1/org.scala-lang/scala-library/2.11.7/f75e7acabd57b213d6f61483240286c07213ec0e/scala-library-2.11.7.jar, /home/adrian/.gradle/caches/modules-2/files-2.1/com.typesafe.sbt/incremental-compiler/0.13.7/8fae2a4f5eb13f1251f8ea742cb0c859208fa1db/incremental-compiler-0.13.7.jar, /home/adrian/.gradle/caches/modules-2/files-2.1/com.typesafe.sbt/compiler-interface/0.13.7/1bac4f222551177cd56b8731351f52576960dde/compiler-interface-0.13.7-sources.jar, /home/adrian/.gradle/caches/modules-2/files-2.1/org.scala-lang/scala-compiler/2.10.4/9e65406822299d082caae78699bb4b64011340ef/scala-compiler-2.10.4.jar, /home/adrian/.gradle/caches/modules-2/files-2.1/com.typesafe.sbt/sbt-interface/0.13.7/2b4ca028f20dd4fccfc134563190f7ef18c4c946/sbt-interface-0.13.7.jar, /home/adrian/.gradle/caches/modules-2/files-2.1/org.scala-lang/scala-reflect/2.10.4/dad1949e8bddc4f97a77025e67d6f0bb2a5071be/scala-reflect-2.10.4.jar]}.

You can see that my scala library version is 2.11.7, but somewhere along the way it decided to use compiler 2.10.4. Upon investigating i discovered that this compiler version is the default for the zinc version being used 0.3.7.

I went digging into the gradle code during a debug and found that the correct version is being found at:

I tried digging in deeper, but got hopelessly bogged down in the myriad closures and not quite objects.

You can try running it for yourself from this code: [] (

I was super excited to see the move to zinc as the standard compiler, but it appears to be broken right now, and i’ll have to force it back to ant if i’m going to use Gradle 2.12.

(Adrian George) #2

Nobody else cares? This was one of the highlighted features of Gradle 2.12 and it just doesn’t work. Worse the hack i had to put in to keep compiling has been marked for removal in 3.0.

(Sterling Greene) #3

Thanks. I think there’s something wrong with the way the Zinc backed compiler figures out which version of the Scala library to use. There’s documentation referring to a scalaTools configuration, but I don’t believe we actually have that anymore.

Does this fix your project (forcing the same version of Scala for all configurations)?

configurations {
    all {
        resolutionStrategy {
            eachDependency { details ->
                if ( == 'org.scala-lang') {
                    details.useVersion '2.11.7' 

I raised GRADLE-3443

(Adrian George) #4

Sorry, I tried this a couple of weeks ago, and got busy and couldn’t comer eport back. Sadly this didn’t fix the problem. I suspect the problem is that i apply scala to all sub projects, but not all subprojects actually have scala. Once again it worked through several of the projects, and then suddenly decided it wouldn’t work anymore. As soon as i nuked my local gradle cache it started failing from the beginning.

EDIT: I might try sticking something in the scala config just in the off chance it still works. When i looked at the source a month or two ago there were still references to it.

(Gary Hale) #5

The issue here is actually the opposite of what might seem intuitive. The issue is not that the compiler is running with an older version of scala-compile, it’s that it’s running with a newer version of scala-library. The problem is that when the scala library is not provided for the zinc compiler, we infer it from the compile configuration. This gets us 2.11.7, but Zinc is compiled against 2.10.X and needs a 2.10 compatible library on its classpath. Note that I’m not referring to the classpath used when compiling classes, but the classpath used when running the Zinc compiler itself.

So, to workaround this issue, we need to explicitly set up the zinc classpath with a version of zinc and the older version of scala-library (to prevent it from trying to get it from the compile configuration):

dependencies {
    zinc 'com.typesafe.zinc:zinc:0.3.9'
    zinc 'org.scala-lang:scala-library:2.10.5'

Note that both of these dependencies are required (it also works with zinc:0.3.7 and scala-library:2.10.4 if you are so inclined). I was able to compile your project with both 2.12 and 2.13 using this workaround, but it would be great if you would confirm.

Inferring the scala-library version from the compile classpath is definitely a defect and will be fixed, but the above should get you past the issue for the short term.

(Adrian George) #6

Awesome, that worked. Thanks a bunch. That is very non-intuitive, because in my debug efforts i kept seeing the wrong compiler being pulled in, weird.

(Amit Ron) #7

I also ran into this issue. strangely the build works with:
repositories {
and fails with jcenter…
The workarounds suggested above did not work for me.