Using Groovy and Java in the same source-sets clobbers the Java classes

If we have a module using the ‘groovy’ plugin and we have both java and groovy under the same source-set, the plugin first compiles the Java classes, then deletes the output and compiles the Groovy classes.

In our case, we tried to separate the code, as we wanted to make sure that the Java classes do not depend on Groovy. As a minimum, Gradle should have warned us. Ideally it should have preserved the Java classes and added the Groovy classes.

Using Gradle Wrapper, Gradle 1.6, JDK 1.6_u33, RHEL 5

I don’t understand what you are saying. To prevent dependencies from Java code on Groovy code, all you have to do is to place the Java code in ‘src/main/java’, and the Groovy code in ‘src/main/groovy’. Same source set, different source directory sets.

Peter, that was my assumption, though when a coleague was doing the same on otherwise vanilla project, we found that when the ‘compileTestJava’ task generates the Java classes in the output dir, but when he called ‘‘compileTestGroovy’’, the Java classes disappeared and the compilation of the Groovy classes failed.

I will try to create a test project and put it on github.

That’s a known problem (but not so easy to fix). It happens after moving Java classes from ‘src/main/groovy’ to ‘src/main/java’. The simplest solution is to delete the ‘$rootProjectDir/.gradle’ directory once.