The Groovy plugin for Gradle claims that it "supports joint compilation, which allows to freely mix and match Groovy and Java code, with dependencies in both directions"
.
However, I don't think this applies to test code.
I have a Java 'sample' test in src/test/java...
which uses a class which is located in src/test/groovy
.
When trying to build with Gradle, I get an error like this:
SwingJavaFXSampleAppTestInJava.java:23: error: cannot find symbol
SwingJavaFXSampleAppTest swingJavaFx = new SwingJavaFXSampleAppTest();
Notice that SwingJavaFXSampleAppTest
is a Groovy class that has not been compiled yet (in the Gradle output I can see that it did not run the compileTestGroovy
before it tried compileTestJava
because the former depends on the latter).
I am able to build this same project with Maven using the groovy-eclipse plugin.
Why does it not work in Gradle when it claims to support compilation in any order, and how can I make it work?
As explained in the Gradle User Guide, only code passed to GroovyCompile
tasks is joint-compiled. So either you put both Java and Groovy code into src/main/groovy
, or you reconfigure the source sets:
sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs = ["src/main/java", "src/main/groovy"]
For tests, replace all occurrences of main
with test
.
You should be able to move your java tests into src/test/groovy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With