I wrote tests for Java8 code (Spring controllers) with using 1.3-groovy-2.4 version of spock-core and spock-spring and everything was fine.
Now we are changing towards to Java11 / groovy 2.5 . So I tried using 1.3-groovy-2.5 but even for minimal tests I get the following error message.
Error:Groovyc: While compiling tests of <project>: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/Users/<me>/.m2/repository/org/spockframework/spock-core/1.3-groovy-2.5/spock-core-1.3-groovy-2.5.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException
IDE IntelliJ 2019.2
jdk1.8.0_152
Groovy Version: 2.5.3 JVM: 11.0.2 Vendor: Oracle Corporation OS: Mac OS X
Apache Maven 3.5.4
Mac 10.14 Mojave
IntelliJ 2019.2
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.3-groovy-2.5</version>
</dependency>
I cannot reproduce this. I do get warnings with the specified setup, but no errors. Maybe it is because I am running it on a Windows machine, but this should not matter.
Do you have a project which I could use to try to reproduce this?
Actually, I have the same issue when I use IDEA 2020.1 , while tests run fine on IDEA 2018.
Error:Groovyc: While compiling tests of insofflineinvest-test: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/Users/jacob/.m2/repository/org/spockframework/spock-core/0.7-groovy-1.8/spock-core-0.7-groovy-1.8.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException
@coderbean your error messages shows that you have Spock 0.7 for Groovy 1.8 in your class path.
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/chigozirim/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-groovy-3.0/396867de1bbbe11e85e197c22f0e6de07643185a/spock-core-2.0-M2-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetException
I use gradle and was getting similar error message. What fixed it for me was to force the use of groovy 3 in build.gradle like this:
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.codehaus.groovy') {
details.useVersion('3.0.3')
}
}
}
}
The exception was java.lang.reflect.InvocationTargetException.
@smac89 Most likely somethings in your Gradle configuration uses Groovy 2.x
Regarding the cryptic error message:
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified ... ASTTransformation because of exception java.lang.reflect.InvocationTargetException
I fixed it in Groovy 3.0.3 - https://github.com/spockframework/spock/issues/1067#issuecomment-599237835 to inform nicer that you mix Groovy versions
Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/chigozirim/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-groovy-3.0/396867de1bbbe11e85e197c22f0e6de07643185a/spock-core-2.0-M2-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.reflect.InvocationTargetExceptionI use gradle and was getting similar error message. What fixed it for me was to force the use of groovy 3 in build.gradle like this:
configurations.all { resolutionStrategy { eachDependency { DependencyResolveDetails details -> if (details.requested.group == 'org.codehaus.groovy') { details.useVersion('3.0.3') } } } }The exception was
java.lang.reflect.InvocationTargetException.
I was having the same issue and this solved it.
My exception was NPE:
Error:Groovyc: While compiling tests of project.test: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/USER_HOME/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.0-M2-groovy-3.0/396867de1bbbe11e85e197c22f0e6de07643185a/spock-core-2.0-M2-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException
Some of the build.gradle:
implementation 'org.codehaus.groovy:groovy:3.0.4'
testImplementation 'org.spockframework:spock-spring:2.0-M2-groovy-3.0'
testImplementation 'org.spockframework:spock-core:2.0-M2-groovy-3.0'
testImplementation 'cglib:cglib-nodep:3.3.0'
test {
useJUnitPlatform()
}
Since there is no issue with Spock I'll close this.
Most helpful comment
I use gradle and was getting similar error message. What fixed it for me was to force the use of groovy 3 in build.gradle like this:
The exception was
java.lang.reflect.InvocationTargetException.