gradlegroovyspock

Gradle Could not find org.codehaus.groovy:groovy:4.0.12


I had to delete my project and recreate it and when I did, I started getting the following error from my gradle build.

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :compileJava
Note: /home/thomas/workspace/util/src/main/java/com/heavyweightsoftware/util/EasyXmlParser.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :compileTestGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestGroovy'.
> Could not resolve all files for configuration ':detachedConfiguration1'.
   > Could not find org.codehaus.groovy:groovy:4.0.12.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/4.0.12/groovy-4.0.12.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :
   > Could not find org.codehaus.groovy:groovy-ant:4.0.12.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-ant/4.0.12/groovy-ant-4.0.12.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :
   > Could not find org.codehaus.groovy:groovy-templates:4.0.12.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-templates/4.0.12/groovy-templates-4.0.12.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 5s
3 actionable tasks: 3 executed

Google the error and found NOTHING... Here is the useful parts of my gradle build.

plugins {
    id 'groovy'
    id 'java'
}

...

apply plugin: 'groovy'
apply plugin: 'java'

...

dependencies {
    implementation (
            'org.apache.groovy:groovy-all:4.0.12',
            'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0',
    )

    testImplementation (
            'org.junit.jupiter:junit-jupiter-api:5.8.1',
            'org.spockframework:spock-core:2.4-M1-groovy-4.0',
            'io.github.joke:spock-mockable:2.3.1',
            'cglib:cglib-nodep:3.3.0'
    )

    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

...

test {
    useJUnitPlatform()
}

I only use groovy for spock testing of my java classes.

Anyone see anything wrong?


Solution

  • If you look at the release notes of Gradle 7.5, you will see that this version added the ability to compile Groovy 4 code.

    As you can see from your build's output, your Gradle version is 6.6.1.

    So your Gradle version is simply too old to build Groovy 4 code.

    If you want to use Groovy 4, you need to update Gradle to at least 7.5.