Spock tests don't run with Gradle 7/Groovy 3?

I’m working on a gradle plugin. I’ve written a spock test for it. With Gradle 6.7 and this configuration:

dependencies {
    implementation gradleApi()

    testImplementation('org.spockframework:spock-core:1.3-groovy-2.5') {
        exclude group: 'org.codehaus.groovy'

    testImplementation gradleTestKit()
    testImplementation 'junit:junit:4.12'

it works just fine. With Gradle 7, I get:

Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/Users/ndw/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/1.3-groovy-2.5/6f0df2cf4549dcc4b914971675da7e224e893e82/spock-core-1.3-groovy-2.5.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception org.spockframework.util.IncompatibleGroovyVersionException: The Spock compiler plugin cannot execute because Spock 1.3.0-groovy-2.5 is not compatible with Groovy 3.0.7. For more information, see http://versioninfo.spockframework.org

If I upgrade to the latest framework:

    testImplementation('org.spockframework:spock-core:2.0-groovy-3.0') {
        exclude group: 'org.codehaus.groovy'

The error message goes away, but gradle test doesn’t run any tests. I mean, it claims to:

> Task :compileJava NO-SOURCE
> Task :compileGroovy
> Task :pluginDescriptors
> Task :processResources
> Task :classes
> Task :pluginUnderTestMetadata
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test

6 actionable tasks: 6 executed

but it doesn’t. There’s no log output here and if I introduce an intentional error in the tests, they still pass. It does appear to be compiling the tests, it just isn’t running them.

You need to switch to using junit 5/platform since spock 2 uses the new test engine.



Thanks. I’ll investigate that. Unfortunately, this is a fork of someone else’s project and I don’t really (yet) understand how Spock and Junit work together.

I found this Testing Gradle plugins but it’s for JUnit 4, Spock 3 and Gradle 7+.

I would really find a complete example with JUnit 5, Spock 3 and Gradle 7 useful, I am not sure I can properly “guess” the right answer here.

To have the answer here too, that example is not with JUnit 4 and Spock 3 does not exist.
It is for Spock 2 which can only run with JUnit 5 platform, except if you use the JUnitPlatform runner for JUnit 4.
That example indeed is a bit a strange if you are not familiar with the things.
The JUnit 4 dependency is superfluous and useless unless you want to use some legacy things like rules from JUnit 4 or @Before annotation for which you then also need the spock-junit4 module. So if you upgrade old tests where you maybe used those legacy things, you might need those dependencies. But to start using Spock it is not the best example and should probably be changed.

I am not able to guess the right answer nor find it. If you know, please share. The question is how to declare the dependencies for Gradle 7+, Groovy 3, Spock 2 and JUnit 5.

Why do you need to guess?
You yourself linked the example you are asking for.