Is it possible to use groovy 4 in gradle plugin tests (spock 2)

Hi!

Gradle 7.6

I want to use spock 2 with groovy 4 in gradle plugin tests (to tests with jdk 16), but it conflicts with gradle’s own groovy 3 (applied from gradleApi())

Configuration excerpt:

plugins {
      id 'java-gradle-plugin'
      id 'groovy'
}

dependencies {
    testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
}

test {
    useJUnitPlatform()
}

java-gradle-plugin applies api gradleApi() which leads to groovy version conflict:

Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/xvik/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.3-groovy-4.0/8861b2590bb8e4709b052fb4ed6da3de98e734d9/spock-core-2.3-groovy-4.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 2.3.0-groovy-4.0 is not compatible with Groovy 3.0.13. For more information (including enforce mode), see https://docs.spockframework.org (section 'Known Issues').
Spock artifact: file:/home/xvik/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/2.3-groovy-4.0/8861b2590bb8e4709b052fb4ed6da3de98e734d9/spock-core-2.3-groovy-4.0.jar
Groovy artifact: file:/home/xvik/.gradle/wrapper/dists/gradle-7.6-bin/9l9tetv7ltxvx3i8an4pb86ye/gradle-7.6/lib/groovy-3.0.13.jar

Is there any way to exclude groovy jars from gradleApi()?
I tried standard exclusions - it doesn’t work.

(spock-core:2.3-groovy-3.0 works without problems)

Full plugin configuration is here: gradle-teavm-plugin/build.gradle at master · xvik/gradle-teavm-plugin · GitHub (changing selected line to groovy 4 leads to fail above)