Getting conflicting module versions for groovy-all after migrating a custom plugin to the worker API

I have written a gradle plugin that works without problems side-by-side with other plugins.

Now I updated the plugin to use the new worker API (mainly for separating the classpath that is used by the plugin). This worked well in general, however in one the projects that uses the updated plugin I get the following exception:

Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing de.obqo.gradle.degraph.DegraphWorker
14:56:11.807 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:107)
14:56:11.808 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:99)
14:56:11.808 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] … 3 more
14:56:11.810 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: java.lang.ExceptionInInitializerError
14:56:11.810 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.classloading.GroovySystemLoaderFactory.forClassLoader(GroovySystemLoaderFactory.java:44)
14:56:11.810 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory.executeInWorkerClassLoader(IsolatedClassloaderWorkerFactory.java:106)
14:56:11.810 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory.access$200(IsolatedClassloaderWorkerFactory.java:56)
14:56:11.810 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1$1.call(IsolatedClassloaderWorkerFactory.java:84)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1$1.call(IsolatedClassloaderWorkerFactory.java:81)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:350)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:340)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:120)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1.execute(IsolatedClassloaderWorkerFactory.java:81)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:105)
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] … 4 more
14:56:11.811 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.4.4 and you are trying to load version 2.4.12

Apparently groovy-all:2.4.4 is a dependecy from another plugin (built with on older gradle version). When I run the build with --debug and the previous version of my plugin then I see that the other plugin pulls groovy-all:2.4.4, and my plugin pulls groovy-all:2.4.12. However, this conflict is apparently resolved by gradle, since there is no exception and both plugins work as expected.

The conflict only shows after I started to use the worker API in my plugin.

According to Controlling conflicting versions of Groovy for a plugin this can be solved by adding

configurations.all { exclude module: “groovy-all” }

to the buildScript closure of the project.

I wonder if this is a bug in gradle (no problem without worker API, but conflict with worker API).
Moreover, can I as the author of the plugin add something to the plugin code, so that the conflict doesn’t show up? It is a bit unfortunate that the users of the plugins need to add extra configuration to their projects to solve this conflict.

For your info - this is the code of the plugin: GitHub - obecker/gradle-degraph: Gradle plugin that executes degraph dependency checks


Update 2018-04-02:
As a workaround I decided to add an explicit compile dependency for org.codehaus.groovy:groovy-all:2.4.12 in the plugin, so gradle is able to do the correct dependency resolution when resolving the plugins. Apparently version conflict resolution doesn’t work between different class loaders. See also the following issues:
Worker classpath should only contain necessary classes · Issue #3698 · gradle/gradle · GitHub and Central plugin classpath management · Issue #1370 · gradle/gradle · GitHub