New post as suggested by Peter Niederwieser : http://forums.gradle.org/gradle/topics/unable_to_force_gradle_to_use_groovy_2_0_0_for_the_project
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'
}
}
Update: ============= Adding this option make the build work Do you know way we have to use this setting with Groovy 2.0?
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-ant:2.0.0',
'org.codehaus.groovy:groovy-test:2.0.0'
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"
}
compileGroovy.groovyOptions.useAnt = true
jar {
println "+Building JAR"
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Implementation-Title': 'HelloWorld'
}
}
# gradle jar
+Building JAR
:compileJava UP-TO-DATE
:compileGroovy
When groovyOptions.useAnt is enabled, options.useAnt must also be enabled. Ignoring options.useAnt = false.
:processResources UP-TO-DATE
:classes
:jar
BUILD SUCCESSFUL
Total time: 14.135 secs