Groovy plugin and mixed Groovy/Java code

(mauromol) #1

Is the groovy plugin (apply plugin: ‘groovy’) supposed to compile Groovy code in src/main/groovy requiring Java code compiled from src/main/java in the classpath?

I mean, suppose I have: src/main/java/ src/main/groovy/ClassB.groovy

If ClassB imports and uses ClassA, is Gradle supposed to build this project correctly? Or am I forced to put ClassA in src/main/groovy in this case?

I would expect that the standard Java compiler compiles src/main/java/ (unless it requires any class from src/main/groovy, of course), while the Groovy compiler, which is run after the Java compiler, compiles the Groovy code in src/main/groovy having the result of the javac compilation from the previous step in the compile classpath.

However, I find myself in a situation in which the Groovy compilation of ClassB fails because it can’t resolve ClassA, which has been compiled immediately before.

Thanks in advance, Mauro.

(Adam Murdoch) #2

Have a look at GRADLE-1190, which describes what you currently need to do to make this work.

(Adam Murdoch) #3

Actually, I misread your question. What you describe should work out of the box. Do you have an error message that shows the problem?

(mauromol) #4

I was able to extract a simple test case that reproduces my problem. Hence I opened GRADLE-1909.