Groovy extension modules do not work with static compilation using the Gradle compiler

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.

1 Like

I see. Is there any example showing how to create a different GroovyCompile task with its own source tree?

p

2 Likes