Gradle upgrade 7.2 > 7.3 breaks with "The value for this property is final and cannot be changed any further" (with Micronaut plugin?)

Viewed 1029

I'm using Micronaut 3.1.3 together with Gradle 7.2 to build my project.

After switching to Gradle 7.3, built breaks emitting some context-free error message:

$ ./gradlew clean build
Executed by Gradle 7.3
- using Java 11.0.13
- using Kotlin 1.5.31
- using Groovy 3.0.9

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project '[PROJECT]'.
> The value for this property is final and cannot be changed any further.

With --stacktrace a very long trace appears. The following excerpt makes me guess that the problem might lay in the Micronaut plugin:

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project '[PROJECT]'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:51)
        [...]
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
Caused by: java.lang.IllegalStateException: The value for this property is final and cannot be changed any further.
        at org.gradle.api.internal.provider.AbstractProperty$FinalizedValue.beforeMutate(AbstractProperty.java:489)
        at org.gradle.api.internal.provider.AbstractProperty.assertCanMutate(AbstractProperty.java:263)
        at org.gradle.api.internal.provider.AbstractProperty.setSupplier(AbstractProperty.java:212)
        at org.gradle.api.internal.provider.DefaultProperty.set(DefaultProperty.java:71)
        at org.gradle.api.tasks.testing.Test.useTestFramework(Test.java:979)
        at org.gradle.api.tasks.testing.Test.useJUnitPlatform(Test.java:1049)
        at org.gradle.api.tasks.testing.Test.useJUnitPlatform(Test.java:1032)
        at io.micronaut.gradle.MicronautLibraryPlugin.lambda$null$1(MicronautLibraryPlugin.java:103)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:123)
        [...]
        at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:201)
        at io.micronaut.gradle.MicronautLibraryPlugin.lambda$apply$4(MicronautLibraryPlugin.java:101)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:123)
        [...]
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)

Cause "problem occurred configuring root project" I'm not sure which part of my build.gradle raises the problem. So following my first guess regarding Micronaut plugin, here is an excerpt telling you the list of plugins in use and config of this plugin:

plugins {
  id('org.jetbrains.kotlin.jvm') version "${kotlinVersion}"
  id('groovy')
  id('org.jetbrains.kotlin.kapt') version "${kotlinVersion}"
  id('com.github.johnrengelman.shadow') version '7.+'
  id('io.micronaut.application') version '2.+'
  id('org.jetbrains.kotlin.plugin.allopen') version "${kotlinVersion}"
  id('com.google.cloud.tools.jib') version '3.+'
  id('org.openapi.generator') version '5.+'
  id('com.heroku.sdk.heroku-gradle') version '2.+'
}

[...]

micronaut {
  runtime('netty')
  testRuntime('spock2')
  processing {
    incremental(true)
    annotations('[PACKAGE]')
  }
}

Maybe this gives enough information to tackle down the cause of the problem? If not please let me know.

Regards

2 Answers

I hit the same issue with my Java build and asked for help on gradle slack channel. It found to be a change in Gradle 7.3 behavior.

This issue contains an explanation of the cause and how to fix it. It helped me to solve the issue with my build: I had options defined in one of the test tasks and then useJUnitPlatform was applied across all test tasks afterwards using this snippet:

tasks.withType(Test).configureEach {
  useJUnitPlatform()    // <-- this line was breaking the build
}

This broke the build after migrating to Gradle 7.3. Removing options solved the problem for me.

Here's an issue requesting to convert this breaking behavior to a warning in Gradle 7.3 and make it a breaking change in 8.0.

FYI: Upgrade to Gradle 7.3.1 brings back successful builds.

Related