org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor encountered while upgrading Groovy and Spock

Solution for org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor encountered while upgrading Groovy and Spock
is Given Below:

Using Gradle 7.1.1, Java 16, Groovy 3.0.8 and Spock 2.0-groovy-3.0

I’m getting this error when running ./gradlew clean test

Caused by: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor
    at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
    at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:673)
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1232)
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
    at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
    at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1383)
    at java.base/java.lang.Iterable.forEach(Iterable.java:74)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:95)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:75)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:97)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    ... 25 more
Caused by: java.lang.NoClassDefFoundError: org/junit/platform/engine/support/discovery/SelectorResolver
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3305)
    at java.base/java.lang.Class.getConstructor0(Class.java:3510)
    at java.base/java.lang.Class.getConstructor(Class.java:2238)
    at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:660)
    at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:657)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
    at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:668)
    ... 36 more
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.discovery.SelectorResolver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    ... 44 more

This is the build.gradle for the module where error is reported:

dependencies {
    implementation 'io.rest-assured:rest-assured'
    implementation 'org.yaml:snakeyaml'
    implementation 'com.fasterxml.jackson.core:jackson-databind'
    testImplementation 'org.junit.jupiter:junit-jupiter'
    testImplementation('org.spockframework:spock-core') {
        transitive = false
    }
}

Parent module build.gradle file:

ext {
    jupiterVersion = '5.7.2'
}

jar.enabled = false

subprojects {
    apply plugin: 'java'
    apply plugin: 'groovy'
    apply plugin: 'codenarc'

    jar.enabled = true

    codenarc {
        toolVersion = '1.4'
        reportFormat="html"
        configFile = new File('../../tool/codenarc/groovy-ruleset.groovy')
    }

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.1") {
                bomProperties(['selenium.version'    : '3.141.59',
                               'rest-assured.version': '4.1.1'])
            }
        }
        dependencies {
            dependency 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
            dependency 'org.spockframework:spock-core:2.0-groovy-3.0'
            dependency 'com.athaydes:spock-reports:2.0-groovy-3.0'
            dependency 'com.codeborne:selenide:5.3.1'
            dependency 'org.hamcrest:hamcrest:2.1'
            dependencySet(group: 'org.junit.jupiter', version: jupiterVersion) {
                entry 'junit-jupiter'
                entry 'junit-jupiter-api'
            }
            dependencySet(group: 'org.slf4j', version: '1.7.28') {
                entry 'jcl-over-slf4j'
                entry 'jul-to-slf4j'
            }
            dependencySet(group: 'org.aspectj', version: '1.9.4') {
                entry 'aspectjrt'
                entry 'aspectjweaver'
            }
            dependency 'io.rest-assured:rest-assured:4.1.1'
            dependency 'org.postgresql:postgresql:42.2.8'
            dependency 'org.yaml:snakeyaml:1.25'
            dependency 'org.apache.poi:poi-ooxml:4.1.1'
            dependency 'com.opencsv:opencsv:4.0'
            dependency 'org.junit.platform:junit-platform-launcher:1.4.0'
        }
    }

    test {
        useJUnitPlatform()
    }
}

Any help would be appreciated.

PS. This was working with Java 11, Groovy 2.5 and Spock 1.3-groovy-2.5

Have you added useJUnitPlatform()?

https://github.com/spockframework/spock-example/blob/master/build.gradle#L34

test {
  useJUnitPlatform()
}

It was a problem with the parent project’s build.gradle file.
I recently upgraded the spring boot version to 2.5.1.
After updating this entry in the build.gradle file the error went away.

    imports {
        mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.1") {
            bomProperties(['selenium.version'    : '3.141.59',
                           'rest-assured.version': '4.1.1'])
        }
    }