Exclude groovy dependency from compile but not from testCompile

I am using groovy for testing, but not for the main classes. So I tried a build file like this:

apply plugin 'groovy'
  dependencies {
    groovy 'org.codehaus.groovy:groovy-all:2.0.5'
}

Listing the dependencies I now find grovy as a dependency in all configurations. So I tried adding

configurations { compile.exclude module:'groovy-all' }

and added:

testCompile 'org.codehaus.groovy:groovy-all:2.0.5'

to the dependencies. Now groovy is gone from all configurations, and I cannot compile my tests. How is this done right?

You need to reshuffle the configuration inheritance…

configurations {

compile.extendsFrom = []

testCompile.extendsFrom groovy

}

Ahh, thanks. Did the job.