GroovyVersionException

I am trying to recompile my project in groovy 2.1 and got following exceptions:

GroovyVersionException: The Spock compiler plugin cannot execute because Spock 0.7.0-groovy-2.0 is not compatible with Groovy 1.8.6. For more information, see http://versioninfo.spockframework.org
Spock location: file:/C:/Users/edvorkin/.gradle/caches/artifacts-23/filestore/org.spockframework/spock-core/0.7-groovy-2.0/jar/4de0b428de0c14b6eb6375d8174f71848cbfc1d7/spock-core-0.7-groovy-2.0.jar
Groovy location: file:/C:/Applications/gradle-1.5/lib/groovy-all-1.8.6.jar

I have groovy 2.1 everywhere in build file and system path.

Here is my build file dependencies:

compile "org.codehaus.groovy:groovy:2.1.3"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"

I don’t understand why gradle still getting groovy from it’s own installation file:/C:/Applications/gradle-1.5/lib/groovy-all-1.8.6.jar. and how to resolve the problem

‘spock-core’ depends on ‘groovy-all’, and it’s not advisable to mix between the latter and ‘groovy’. Either switch to ‘groovy-all’, or exclude it. This doesn’t explain how 1.8.6 comes in though. You can try ‘gradle dependencyInsight --configuration testRuntime --dependency groovy-all’. If this doesn’t show 1.8.6, then my best guess is that you use ‘localGroovy()’ somewhere. Perhaps in a parent build script, or in an ‘init.gradle’ in your Gradle user home.

Hi Peter, Thanks for quick response.

I have updated my build file to groovy-all and removed groovy.

But this does not resolve the problem

$ gradle dependencyInsight --configuration testRuntime --dependency groovy-all
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read htt
on the replacement for dynamic properties.
Deprecated dynamic property: "applicationName" on "root project 'CommunicationsPlatform'", value: "cp".
Deprecated dynamic property: "artifactId" on "root project 'CommunicationsPlatform'", value: "cpeventservice".
Deprecated dynamic property: "env" on "task ':test'", value: "null".
:dependencyInsight
org.codehaus.groovy:groovy-all:2.1.3 (conflict resolution)
\--- testRuntime
  org.codehaus.groovy:groovy-all:2.0.5 -> 2.1.3
\--- org.spockframework:spock-core:0.7-groovy-2.0
     +--- testRuntime
     \--- org.spockframework:spock-spring:0.7-groovy-2.0
          \--- testRuntime
  (*) - dependencies omitted (listed previously)
  BUILD SUCCESSFUL
  Total time: 6.525 secs

But my problem still exists:

$ gradle
 -Dtest.single=*Test test
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for informati
on the replacement for dynamic properties.
Deprecated dynamic property: "applicationName" on "root project 'CommunicationsPlatform'", value: "cp".
Deprecated dynamic property: "artifactId" on "root project 'CommunicationsPlatform'", value: "cpeventservice".
Deprecated dynamic property: "env" on "task ':test'", value: "null".
:compileJava SKIPPED
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy
startup failed:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/C:/Users/edvorkin/.gradle/caches/artifacts-23/filestore/org.spockframework/spock-core/0.7-groovy-2.0/jar/4de0b428de0c14b6eb637
174f71848cbfc1d7/spock-core-0.7-groovy-2.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
because of exception org.spockframework.util.IncompatibleGroovyVersionException: The Spock compiler plugin cannot execute
ause Spock 0.7.0-groovy-2.0 is not compatible with Groovy 1.8.6. For more information, see http://versioninfo.spockframework.org
Spock location: file:/C:/Users/edvorkin/.gradle/caches/artifacts-23/filestore/org.spockframework/spock-core/0.7-groovy-2.0/jar/4de0b428de0c14b6eb6375d8174f71848cbfc1d7/spock-core-0.7-groovy-2.0.jar
Groovy location: file:/C:/Applications/gradle-1.5/lib/groovy-all-1.8.6.jar
  1 error
  :compileTestGroovy FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':compileTestGroovy'.
> Compilation failed; see the compiler error output for details.

I don’t have any localGroovy declaration not I have init.gradle file

$ find
C:/Users/edvorkin/.gradle -name init.gradle

The problem is likely caused by your build or environment. Try to reproduce on another machine. If the problem persists, please provide a standalone reproducible example.

If you look closely you will see that spock is complaining about gradle’s own groovy jar. The one we have no control over via the build.gradle file. Ergo, we can not remove it unless we do so manually after installing a fresh gradle making it effectively a non standard gradle installation.

You do have control over it. The only way for this Groovy Jar to get on the test compile class path is to explicitly put it there, e.g. by using ‘dependencies { testCompile groovyLocal() }’.

I wasn’t. At least not knowingly. I think gradleApi() is pulling it in but that construct does not allow me to exclude it like with normal dependencies.

That is, I tried: compile gradleApi(), {exclude …} compile gradleApi({exclude …})

neither work.

I also looked for gradle-core on maven central so I could add the dependency without resorting to gradleApi() and thus being able to exclude unwanted dependencies but it isn’t there.

I also came across this problem and eventually noticed that using the gradle wrapper fixed it for me (i’m using wrapper version 2.0). The gradleApi() obviously uses groovy-all jar bundled with gradle - and I was invoking the gradle build without the wrapper and using version 1.9 (which uses groovy 1.8.6).

I am facing this problem right now, kind of on the opposite side - Groovy is too new:

Spock 0.7.0-groovy-1.8 is not compatible with Groovy 2.3.6.

I went through a few iterations of this:

  1. My gradle wrapper was from 1.8 but it was pointed to 2.1.

  2. Downloaded gradle 2.1 and ran it directly (i.e. no wrapper), keeping .gradle in my home.

  3. Deleted .gradle in my home directory, ran the downloaded gradle 2.1 directly.

There is absolutely no mention of groovyLocal or any groovy setting anywhere. My project does not use this “spock” thing anywhere, for anything. Whatever task I try to build, e.g. “wrapper” fails…

My details (some identifying stuff censored):

(tried to edit this post to make it not clobber the console output but nothing work - things show twice)

C:\src\... c:\util\gradle\bin\gradle dependencyInsight --configuration testRuntime --dependency groovy-all
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
...
FAILURE: Build failed with an exception.
  * Where:
Build file 'C:\src\...\build.gradle'
  * What went wrong:
Could not compile build file 'C:\src\...'.
 startup failed:
  Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/C:/Users/.../.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/0.7-groovy-1.8/3a677d19e8d3acf3bd296c4023356256d55da5a3/spock-core-0.7-groovy-1.8.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
because of exception org.spockframework.util.IncompatibleGroovyVersionException: The Spock compiler plugin cannot execute because
Spock 0.7.0-groovy-1.8 is not compatible with Groovy 2.3.6. For more information, see http://versioninfo.spockframework.org
Spock location: file:/C:/Users/.../.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/0.7-groovy-1.8/3a677d19e8d3acf3bd296c4023356256d55da5a3/spock-core-0.7-groovy-1.8.jar
Groovy location: file:/C:/util/gradle/lib/groovy-all-2.3.6.jar
    1 error
    * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED

The combination that worked for me was using gradle wrapper 2.0 and the following dependencies

dependencies {
        compile gradleApi()
        compile "org.codehaus.groovy:groovy-all:2.3.3"
        testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
        testRuntime "cglib:cglib-nodep:2.2.2"
        testCompile 'org.mockito:mockito-all:1.8.4'
        compile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
}

I found the cause in my case. My build used plugins that indirectly referenced other versions of artifacts gradle itself needs. Once I removed or updated the versions of these plugins all started working.

@Learner

what were some of the plugins you were referencing in your project as I’m tracing down this same issue right now in various projects I have.

Update was it “com.github.goldin.plugins.gradle:duplicates” if so what do you do instead?