No
Is the extension module allowed to exist in the same compilation unit where itâs being used?
That was exactly what I was going to say. It has to be in a separate source tree.
Moving the main class to âsrc/test/groovyâ solved the compilation problem. An extension module cannot be used from the same compilation unit where itâs defined.
Thanks Cédric.
I see. I didnât know that. Actually IntelliJ is able to compile it with no problem, so I was supposing that Gradle should be able as well.
Sorry if Iâm insisting with this, but I still havenât would a valid solution to this problem.
Obviously I canât put my code in the test folder. How to define a separate compilation unit with Gradle? Does it mean that I need to put in a separate (sub) project?
Cheer, Paolo
Yes. Basically, an extension module has to be precompiled before being used. So if you use it in the same module (or subproject, whatever the name we use) it is defined in, it will fail. What Peter says is basically that if you use it in tests, then you have de facto two distinct compilation phases (one for main classes, one for tests) so it works.
An option would be to create a different GroovyCompile task for your extension module, in a distinct source tree. The other would be to have a distinct subproject.
I see. Is there any example showing how to create a different GroovyCompile task with its own source tree?
p