1

Until Gradle 7, I could use the following block in my build script to trigger Gradle to use a specific Java version independently of my runtime JDK (in this case, java11):

java {
    toolchain {
            languageVersion = JavaLanguageVersion.of(11)
    }
}

And thanks to this block, I could compile my project even with org.gradle.java.home pointing at my jdk17 path.

After upgrading to Gradle 8.1.1, I get this error message:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\dev\workspace\foo\bar\build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':baz'.
> The value for property 'languageVersion' is final and cannot be changed any further.

To make matters worse, the official Gradle documentation suggests to use my exact snippet to solve this problem, which obviously doesn't work.

I couldn't find any working code snippets apart from setting ´java.sourceCompatibility = JavaVersion.VERSION_11´, which doesn't allow me to compile without first changing org.gradle.java.home to point at my jdk11.

TdrFlp
  • 54
  • 1
  • 6
  • I guess this may lead you to a solution https://stackoverflow.com/questions/69939935/gradle-upgrade-7-2-7-3-breaks-with-the-value-for-this-property-is-final-and-c – cool Jun 23 '23 at 12:11

1 Answers1

0

I have:

------------------------------------------------------------
Gradle 8.1.1
------------------------------------------------------------

Build time:   2023-04-21 12:31:26 UTC
Revision:     1cf537a851c635c364a4214885f8b9798051175b

Kotlin:       1.8.10
Groovy:       3.0.15
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.12 (Azul Systems, Inc. 11.0.12+7-LTS)
OS:           Windows 10 10.0 amd64

I tried your snippet with the following build.gradle and the build was 'Success':

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

test {
    useJUnitPlatform()
}
3AKOBAH
  • 105
  • 6
  • My setting is a multi-project build, though. That's probably the issue then. I'll try again from the top-level project (which is just a placeholder) – TdrFlp Jun 26 '23 at 09:30