Using groovy 4.0.26 in a Gradle plugin

I am trying to create a gradle plugin for my groovy library that depends on groovy 4.0.26. I understand that the groovy plugin code itself must adhere to the bundled groovy version (3.0.22 for Gradle 8.13) but is it possible to get rid of the groovy in the gradle classpath and use 4.0.26 instead in the actual execution of the plugin? Creating a child first classloader and dynamically fetch the dependencies and then call my library is quite a lot of work - hopefully there is a simpler way…

Creating a child first classloader and dynamically fetch the dependencies and then call my library is quite a lot of work

And illegal.
A “child first” classloader violates the class loader contract.

I don’t think you can “get rid” of the Groovy in the classpath as that is part of the top-most class loader.
But you can get an ExecOperations instance injected to your plugin and then use javaExec on it to execute your code out-of-process, where you have full control over the classpath.

1 Like