How do I fix the "Spock 1.0.0-groovy-2.4 is not compatible with Groovy 2.3.10" error?

(Martin d'Anjou) #1

Groovy 2.3.10 is not compatible with Spock 1.0.0-groovy-2.4, but I don’t know how to address this problem. Can someone help me please?

Here is the build.gradle file:

apply plugin: "groovy"

repositories {

dependencies {
  // Get the gradle api definitions
  // I will be writing a gradle plugin, so I figure I need this
  compile gradleApi()
  compile 'org.codehaus.groovy:groovy-all:2.4.3'
  testCompile 'org.codehaus.groovy:groovy-all:2.4.3'
  compile ('org.spockframework:spock-core:1.0-groovy-2.4') {
    exclude group: 'org.codehaus.groovy'

task wrapper(type: Wrapper) {
  gradleVersion = "2.4"

Now when I type ./gradlew test, I get:

The Spock compiler plugin cannot execute because Spock 1.0.0-groovy-2.4 is not compatible with Groovy 2.3.10.

More info:
./gradlew --version

Gradle 2.4

Build time:   2015-05-05 08:09:24 UTC
Build number: none
Revision:     5c9c3bc20ca1c281ac7972643f1e2d190f2c943c

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM:          1.8.0_40 (Oracle Corporation 25.40-b25)
OS:           Linux 2.6.32-358.el6.x86_64 amd64

In case it helps, the test looks like this:

import spock.lang.Specification
class HelloWorldPluginSpec extends Specification {
  def 'can call helloWorld'() {
      project.apply HelloWorldPlugin

(Mark Vieira) #2

You should really be using Groovy 2.3 here. Since this is going to be a Gradle plugin and use Gradle’s version of Groovy at runtime you should be compiling and testing against the Gradle Groovy distribution. In practice, it’s best to use the localGroovy() dependency notation to ensure this.

(Martin d'Anjou) #3

Thank you!
Posting the fix:

apply plugin: "groovy"

repositories {

dependencies {
  compile gradleApi()
  compile localGroovy()

  // A test framework
  compile ('org.spockframework:spock-core:1.0-groovy-2.3')

task wrapper(type: Wrapper) {
  gradleVersion = "2.4"

(Schalk Cronjé) #4

On a technical note, I think Spockframework should be in the testCompile configuration, otherwise your released plugin will have a dependency on SpockFw

(Steve Cohen) #5

I have similar issue trying to run gradle in Eclipse. Nothing in my code seems to ask for groovy 2.4 but somehow gradle is pulling it in. I know this because my “Gradle Dependencies (persisted)” includes groovy-all-2.4.4.jar. It seems that this is being pulled in via gradle 2.11.

Eclipse pulls in untwanted 2.4.4 version of Groovy causing error
(Levon Saldamli) #6

I have the same problem. Groovy Eclipse only has compiler versions up to 2.4.3, but Gradle pulls in 2.4.4 which breaks running unit tests in Eclipse.Forcing groovy-all 2.4.3 with resolutionStrategy didn’t work either.

(Steve Cohen) #7

You should be able to find the Groovy Eclipse support you need here: I just did this yesterday with a new install of Mars.

(Levon Saldamli) #8

I’ve tried the latest groovy eclipse for mars, it had only up to 2.4.3. Or
can you find any build that has 2.4.4 compiler?

(Steve Cohen) #9

Yeah, you’re right.I had problems with that months ago, see my earlier post, but I don’t see them anymore. I assumed this was because my plugin install pulled them in, but it didn’t. I only have up to 2.4.3 but nothing complains about that anymore. Not sure why. Sorry I couldn’t be more helpful.

(Schalk Cronjé) #10

If you are building a plugin and don’t need the absolute llatest API functionality, your workaround is simply to use an older version of Gradle which will have 2.4.3 as it’s dependency.

(Levon Saldamli) #11

Yes, I considered that. Going back to gradle 2.7 (2.6?) goes back to groovy
2.3.6. Unfortunately, the jump is from 2.3.6 to 2.4.4. I guess that is the
only option though. Even than it is a matter of having luck that gradle
2.3.x and the greclipse compiler 2.3.x matches.

(Schalk Cronjé) #12

The jump happened at 2.8:

  • 2.7 -> 2.3.10
  • 2.8 -> 2.4.4

Also, what I tend to have in the buildscript is

ext {
    spockGroovyVer = GroovySystem.version.replaceAll(/\.\d+$/,'')
dependencies {
   testCompile ("org.spockframework:spock-core:1.0-groovy-${spockGroovyVer}") {
      exclude module : 'groovy-all'

It sorts out Spock dependency name and it prevents Spock transitive dependencies from injecting an alternative Groovy version.

Unfortunately as I don’t use Eclipse, I’m not sure if this will help you.

(Levon Saldamli) #13

I’m not sure it will help since there is a runtime check when running spock (or groovy?) that checks for exact match between groovy versions, i.e. for the groovy loaded in Eclipse and the groovy in the dependency list of the gradle project. But I will try it, thanks!

(Philip Cheong) #14

I’m trying to migrate integration tests written in junit to spock. I’m using gradle 3.0 and hit this error with 1.1-groovy-2.4-rc-2

Conflicting module versions. Module [groovy-all is loaded in version 2.4.7 and you are trying to load version 2.4.6

But then I discovered this trick:

I don’t know what @jar does but it fixes the dependency conflict in my build.

(Schalk Cronjé) #15

You need to have this

testCompile 'org.spockframework:spock-core:1.0-groovy-2.4', {
  exclude module : 'groovy-all'

This will ensure that the transitive dependency of Groovy that Spock has do not get included, but rather the one that you specified in compile.

(Philip Cheong) #16

@Schalk_Cronje I get some kind of syntax error. Here is the code I tried:

dependencies {
    testCompile ( 
        'org.spockframework:spock-core:1.1-groovy-2.4-rc-2', {exclude module : 'groovy-all'},

Also tried this:

dependencies {
    testCompile ( 
    ) {exclude module : 'groovy-all'}

I get the same error in both cases:

  • What went wrong:
    A problem occurred evaluating root project ‘gradle-build-test’.

Cannot convert the provided notation to an object of type Dependency: build_dx1mkix5t1nts8t1hab7cczhv$_run_closure4$_closure13@16e1b652.
The following types/formats are supported:
- Instances of Dependency.
- String or CharSequence values, for example ‘org.gradle:gradle-core:1.0’.
- Maps, for example [group: ‘org.gradle’, name: ‘gradle-core’, version: ‘1.0’].
- FileCollections, for example files(‘some.jar’, ‘someOther.jar’).
- Projects, for example project(’:some:project:path’).
- ClassPathNotation, for example gradleApi().

What is wrong with the @jar notation?

(Schalk Cronjé) #17

The syntax is wrong. Also for purpose of readability it is better to restrict place each dependency on a separate line along with the configuration it belogns to. i.e.


testCompile 'junit:junit:4.12'
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-2'


testCompile 'junit:junit:4.12', 'org.spockframework:spock-core:1.1-groovy-2.4-rc-2'

Anyway what you need in your case is

testCompile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-2', {
  exclude module : 'groovy-all'
testCompile gradleTestKit()

You should not need anything else as Spock already has JUnit as a transitive dependency.

(Philip Cheong) #18

Ah great thanks @Schalk_Cronje that fixed it for me!