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

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 {
  mavenCentral()
}

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'() {
    when:
      project.apply HelloWorldPlugin
    then:
      project.tasks.getByName('helloWorld')
  }
}

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.

Thank you!
Posting the fix:

apply plugin: "groovy"

repositories {
  mavenCentral()
}

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"
}

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

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.

1 Like

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.

You should be able to find the Groovy Eclipse support you need here: https://github.com/groovy/groovy-eclipse/wiki. I just did this yesterday with a new install of Mars.

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?

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.

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.

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.

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.

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!

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.

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.

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

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

Also tried this:

dependencies {
    testCompile ( 
        'junit:junit:4.12',
        'org.spockframework:spock-core:1.1-groovy-2.4-rc-2', 
        gradleTestKit()
    ) {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?

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.

Prefer

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

over

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.

Ah great thanks @Schalk_Cronje that fixed it for me!

You can also try adding
'org.codehaus.groovy:groovy:2.3.10',
in testCompile.