Unable to force Gradle to use Groovy 2.0.0 for the project

I’m playing with Groovy 2.0.0 to build my project and run tests. My build.gradle looks like:

apply plugin: 'groovy'
   repositories {
    mavenCentral()
    maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
   dependencies {
    compile gradleApi() //it is a plugin for Gradle
    groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.0.0'
    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0-SNAPSHOT'
    (...)
}

I end with:

Test initializationError(info.solidsoft.gradle.pitest.PitestPluginSpockTest) FAILED: org.spockframework.util.IncompatibleGroovyVersionException: The Spock JUnit runner 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:/home/foo/.gradle/caches/artifacts-13/filestore/org.spockframework/spock-core/0.7-groovy-2.0-SNAPSHOT/jar/ca755d85f147f148392d9ebecc99eb86adcaa994/spock-core-0.7-groovy-2.0-SNAPSHOT.jar
Groovy location: file:/opt/gradle-1.0/lib/groovy-all-1.8.6.jar

From a debug log there is still groovy-all-1.8.6.jar on an application classpath (log by DefaultWorkerProcessFactory) before groovy-all-2.0.0.jar which is placed later.

Is there something more needed to use Groovy 2.0?

‘gradleApi’ drags in the Groovy version that ships with Gradle, which is currently 1.8.6. Because ‘gradleApi’ is a special kind of dependency, there is no version conflict resolution as it would normally occur. When writing a Gradle plugin, you should use ‘groovy localGroovy()’, which again is 1.8.6 for recent versions of Gradle. You can’t currently use Groovy 2.0 for writing plugins.

Thanks Peter for your clarifications.

I have also tried this with the gradle 1.1rc and it also give the same error, is this going to be fixed in the final release of gradle 1.1?

Thanks in advance for the help.

What error are you referring to? As I said, you can’t use Groovy 2.0 for developing Gradle plugins.

Well actually I am not building a Gradle plugin, I am trying to build a Groovy 2.0 app (jar) and it fails with the following error:

  Execution failed for task ‘:compileGroovy’.  > BUG! exception in phase ‘class generation’ in source unit ‘/test/src/main/groovy/HelloWorld.groovy’ ClassNode#getTypeClass for org.slf4j.Logger is called before the type class is set

The strange thing is that it work with Groovy 1.8.6

Here is an example:

_____build.gradle
|____src
| |____main
| | |____groovy
| | | |____HelloWorld.groovy
| | |____java
| | |____resources
| |____test
| | |____groovy
| | |____java
| | |____resources

HelloWorld.groovy:

import org.codehaus.groovy.transform.*
import org.slf4j.*
import groovy.util.logging.*
import ch.qos.logback.classic.*
import static ch.qos.logback.classic.Level.*
  @Slf4j
class HelloWorld {
  HelloWorld() { log.info "Initialization ${this.class.name}" }
    static main(args) { def main = new HelloWorld() }
}

build.gradle

apply plugin:'groovy'
group = 'HelloWorld'
archivesBaseName = 'HelloWorld'
  repositories {
  mavenLocal()
  mavenCentral()
}
dependencies {
    groovy 'org.codehaus.groovy:groovy:2.0.0',
           'org.codehaus.groovy:groovy-test:2.0.0'
           //'org.codehaus.groovy:groovy-all:2.0.0' also tried this an still get the same error
  //groovy 'org.codehaus.groovy:groovy:1.8.6'
  compile "org.slf4j:slf4j-api:1.6.6",
          "ch.qos.logback:logback-core:1.0.6",
          "ch.qos.logback:logback-classic:1.0.6"
    testCompile "junit:junit:4.10"
}
jar {
  println "+Building JAR"
  from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
  manifest {
    attributes 'Implementation-Title': 'HelloWorld'
  }
}

Please create a new topic. Sounds like a problem with Groovy’s @Slf4j transform. Can you compile this with ‘compileGroovy.groovyOptions.useAnt = true’ or plain ‘groovyc’?

This option did the trick :wink: Just for you’re info, yes it compiles correctly when using the plain groovyc