How to use Groovy 2.0 for gradle 1.2 build? Got 1.8.6 pulled instead

I have following error when building my spplication:

Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/C:/Users/edvorkin/.gradle/caches/artifacts-14/filestore/org.spockframework/spock-core/0.7-groovy-2.0/jar/4de0b428de0c14b6eb6375d8174f71848cbfc1d7/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 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-14/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.2/lib/groovy-all-1.8.6.jar
  1 error
   FAILED

In my build script I reference groovy-all.2.0.4 and groovy is in my path. how can I force gradle to use groovy 2.0 instead of groovy 1.8?

Thanks

Can you please show your Groovy dependency declaration? How are you getting ‘file:/C:/Applications/gradle-1.2/lib/groovy-all-1.8.6.jar’ on the class path? Are you using ‘groovyLocal()’ or ‘gradleApi()’ dependencies?

// for spock testing
configurations.all {
 resolutionStrategy {
   force "org.codehaus.groovy:groovy:2.0.4"
 }
  }
   dependencies {
 //groovy group: 'org.codehaus.groovy', name: 'groovy', version: '2.0.5'
 groovy group: 'org.apache.ivy', name:'ivy', version:'2.2.0'
       compile "org.springframework:spring-webmvc:${springframework_version}"
 compile "org.springframework:spring-context:${springframework_version}"
 compile "org.springframework:spring-aop:${springframework_version}"
 testCompile "org.springframework:spring-test:${springframework_version}"
 compile "log4j:log4j:1.2.14"
    compile "org.springframework.data:spring-data-mongodb:1.0.2.RELEASE"
 compile "org.springframework.data:spring-data-commons-core:1.2.0.RELEASE"
 compile "org.codehaus.groovy:groovy-all:2.0.4"
 compile "cglib:cglib-nodep:2.2"
 compile "joda-time:joda-time:2.0"
 compile "javax.servlet:jstl:1.2"
 compile "org.codehaus.jackson:jackson-core-asl:1.9.9"
 compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.9'
               testCompile "junit:junit:4.9"
    testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
 testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
 testCompile "org.objenesis:objenesis:1.2"
 testCompile "org.hamcrest:hamcrest-core:1.2"
    testCompile "org.codehaus.groovy.modules.http-builder:http-builder:0.5.2"
 testCompile "org.seleniumhq.selenium:selenium-firefox-driver:2.25.0"
     testCompile "org.seleniumhq.selenium:selenium-java:2.25.0"
    compile "javax.servlet:servlet-api:2.5"
 compile "javax.servlet.jsp:jsp-api:2.1"
 compile "org.aspectj:aspectjrt:1.6.12"
 compile "org.aspectj:aspectjweaver:1.6.12"
 testCompile "ojdbc:ojdbc:6"
        }

I did not declare groovyLocal(). How to do so?

A couple of hints:

  • You add ‘groovy-all’, but force ‘groovy’ * Somewhere, you must be adding Groovy to the ‘groovy’ configuration (otherwise compilation would fail), and apparently you add ‘groovyLocal()’ (which in your case you shouldn’t). Is this a multi-project build? * Why do you add Ivy to the ‘groovy’ configuration? Is this for ‘@Grab’? If not, you should get rid of this.

PS: In general, it’s safer to use ‘groovy-all’ than ‘groovy’, because the former packages shaded versions of its dependencies (e.g. ASM).

Thank you Peter, This is not a multiproject build. I am not adding anything to groovy configuration except

apply plugin: 'groovy'

and dependencies.

I am using iVy because of

buildscript {
 apply from: 'https://github.com/valkolovos/gradle_cobertura/raw/master/repo/gradle_cobertura/gradle_cobertura/1.0/coberturainit.gradle'
}

to get cobertura plugin. Removing force groovy did not help. Is it possible that the problem somewhere outside of build file?

Thanks

There could always be a ‘~/.gradle/init.gradle’ interfering, but I doubt that’s the case. Have you tried to remove the Cobertura plugin? Besides, you shouldn’t need to put Ivy on the ‘groovy’ configuration in order to get the Cobertura plugin to work.