Controlling conflicting versions of Groovy for a plugin

Normally when testing a plugin with Spock

testCompile ('org.spockframework:spock-core:0.7-groovy-2.0') {
        exclude module : 'groovy-all'
    }

is good enough to resolve conflicts.

However, when the plugin is also dependent on a another subproject in a multi-project build this is not good enough. Consider

compile project(":another")
     testCompile ('org.spockframework:spock-core:0.7-groovy-2.0') {
        exclude module : 'groovy-all'
    }

Let’s just say ‘another’ will accept a range of groovy versions from 2.0-2.5. This causes version conflicts. I’ve tried to do something like

configurations.all {
    def gr = project.dependencies.localGroovy()
    resolutionStrategy.force "${gr.group}:${gr.name}:${gr.version}"
}

to force it to the local Groovy version, but the problem persists.

Any idea how one can manage the version conflict in this case? (I don’t want to change the ‘another’ subproject).

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

Hey ho, that works.

I guess we can get away with this here, because ‘groovy-all’ will be on the classpath due to ‘localGroovy()’.

BTW this can also work by adding a configuration to ‘another’ like

configurations {
    noGroovy {
        extendsFrom configurations.default
        exclude module : 'groovy-all'
    }
}

then in the plugin project do

compile project( path:':dsl',configuration:'noGroovy')