Is there a way to use groovy/spock for testing an all java project without polluting the runtime dependencies with groovy?


(Matias Bjarland) #1

I am aware that I can use the groovy plugin to set this up and we are using spock this way for a number of our projects, but is there a way to do this without polluting the ‘compile’ and ‘runtime’ dependencies of the project with groovy artifacts?

In other words, is there a way to use groovy and spock for testing only and keep the external surface of the java project free of all traces of groovy?


(Matias Bjarland) #2

Answering my own question here. It seems that the following pattern:

apply plugin: 'groovy'
  ...
  configurations.default.exclude group: 'org.codehaus.groovy', module: 'groovy-all'
  dependencies {
  groovy "org.codehaus.groovy:groovy-all:1.8.8"
...
}

does the trick. Gradle gurus, chime in if there is a better way. I saw the following comment on the groovy plugin:

footnote on ‘the groovy plugin can even deal with java only projects’: > > [9] We don’t recommend this, as the Groovy plugin uses the Groovyc Ant task to compile the sources. For pure Java projects you might rather stick with javac. In particular as you would have to supply a groovy jar for doing this.

so even with my exclude above, we are still using the wrong compiler.


(Peter Niederwieser) #3

Excluding Groovy from the ‘default’ configuration is not enough. I’d do something like:

configurations.compile.extendsFrom = [] // undo what Groovy plugin does
configurations.testCompile.extendsFrom(configurations.groovy)

I expect that in a future version, the Groovy plugin will do better than simply putting the Groovy library on the ‘compile’ configuration.


(Matias Bjarland) #4

Thanks. That works.


(Dimitar Dimitrov) #5

PN >> I expect that in a future version, the Groovy plugin will do better than simply putting the Groovy library on the compile configuration.

Is there any JIRA that I can watch?


(Peter Niederwieser) #6

The feature was already delivered in Gradle 1.4. See the release notes.