javagradlegroovygroovyfx

Gradle Migration Issue


Upgrading a project from Java 8 to OpenJDK 17, I got an error. Here is the build.gradle.

configurations {
    jansi.extendsFrom(runtime)
}

sourceSets {
    demo {
        compileClasspath += sourceSets.main.output + configurations.compile
        runtimeClasspath += sourceSets.main.output
        groovy {
            srcDir 'src/demo/groovy'
        }
        resources {
            srcDir 'src/demo/resources'
        }
    }
}

The issue should be related to configurations.compile.

This is the error I got:

Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'compile' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.
    at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
    at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:62)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer_Decorated.getProperty(Unknown Source)
    at build_27astx6mawktv5quhzm1qq681$_run_closure10$_closure38.doCall(C:\Temp\groovyfx\build.gradle:208)

Project main page. The build.gradle file is here.


Solution

  • The configuration compile was deprecated for many years and was finally removed in Gradle 7.0.

    As a general advice, I'd like to recommend switching to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

    Regarding upgrading Gradle, I recommend to first upgrade to the latest patch version within the same Gradle major version, then fix all deprecation warnings, then update to the latest patch version within the next Gradle major version - thereby also following the upgrade notes in the userguide, and then repeat this process until you are on the Gradle version you want to upgrade to. This usually results in a smooth Gradle upgrade experience.

    In your case you might want to use compileClasspath instead of compile most probably.