Project mixing scala and groovy does not compile with gradle 4.0

(Felix) #1


I have a scala project that uses a tiny bit of groovy source code (a single class to be precisely). I am applying the groovy plugin; and the sources are locates in src/main/scala and src/main/groovy. This used to work fine, however when I gave 4.0 a shot I got this error:

> Task :XXX:YYY:compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
/path/to/some/ScalaSourceFile.scala:162: not found: type SomeClassWrittenInGroovy

where SomeClassWrittenInGroovy is located under src/main/groovy

–debug reveals that the -classpath passed to the scala compiler doesn’t include build/classes/groovy/main:

16:13:41.369 [DEBUG] [org.gradle.api.internal.tasks.scala.ZincScalaCompiler] Calling Scala compiler with arguments  (CompilerInterface):

Now how can I make the scala compiler to include /MY_PROJECT_HOME/XX/YY/build/classes/groovy/main into -classpath ?

(Felix) #2

So I followed the suggestion in the release notes and added this to my build file:

sourceSets.main.output.classesDir = new File(buildDir, "classes/main")

which helps. It turns out that the message Pruning sources from previous analysis, due to incompatible CompileSetup. was not related to the issue.

Anyway, this is just a workaround, so I would still like to understand how I can control the class path of the scala compiler task or how to enable joint compilation of scala and groovy sources. Anyone?

(Sterling Greene) #3

Did you have any other configuration in your build before?
e.g., something like

compileScala.dependsOn compileGroovy

(Felix) #4

No, just the apply plugin: statements.
So I gave it a shot but the result is the same. The groovy classes dir is still not passed with -classpath.

(Sterling Greene) #5

Sorry, I didn’t mean to imply that would fix it.

This used to work because all compilation tasks shared the same output directory, so depending on the order that the compilation tasks would run, you could depend on classes from earlier compilation tasks.

Since there was no relationship between compileGroovy and compileScala, you were getting lucky that Groovy compilation would happen before Scala compilation.

I’ve opened an issue for this:

As a different workaround, you could do this:

compileScala {
    classpath =
    dependsOn compileGroovy

This explicitly adds the Groovy compilation output directory to the classpath for Scala.