repo/toolchain-pinned/java
Toolchain version is pinned
Implements repo/toolchain-pinned for java.
| Severity | warning |
| Tiers | 1, 2 |
| Stacks | java |
| Scope | each |
| Kind | expr |
| Source | library v0.2.0 |
| Selected by | fleetlint-recommended@v0.2.0 |
Requirement
The JDK is pinned: .java-version, .sdkmanrc with java=, a Gradle toolchain in the project’s or a parent build (JavaLanguageVersion.of(n), jvmToolchain(n)) or gradle-daemon-jvm.properties, the Maven enforcer’s requireJavaVersion, or .tool-versions/mise naming java. The Gradle and Maven wrappers pin the build tool, not the JDK, and maven.compiler.release only sets the bytecode level; none of them counts.
Why
Without a pin, every machine and every CI run builds with whatever compiler or runtime happens to be installed, and failures cannot be reproduced.
Check
["", "../", "../../", "../../../"].exists(d, file(d + ".java-version") && scan(d + ".java-version", r'^\s*\S*\d').size() > 0) || ["", "../", "../../", "../../../"].exists(d, file(d + ".sdkmanrc") && scan(d + ".sdkmanrc", r'^\s*java\s*=\s*\d').size() > 0) || ["", "../", "../../", "../../../"].exists(d, file(d + "gradle/gradle-daemon-jvm.properties") && text(d + "gradle/gradle-daemon-jvm.properties").matches(r'toolchainVersion\s*=\s*\d')) || (glob("**/build.gradle*") + ["../", "../../", "../../../"].map(d, [d + "build.gradle", d + "build.gradle.kts"]).flatten().filter(f, file(f)))
.exists(f, text(f).matches(r'languageVersion(\.set\(|\s*=\s*)\s*JavaLanguageVersion\.of\(\s*\d|jvmToolchain\s*\(\s*\d'))
|| ["", "../", "../../", "../../../"].exists(d, file(d + "pom.xml") && text(d + "pom.xml").matches(r'<requireJavaVersion>\s*<version>\s*[\[(]?\d')) || ["", "../", "../../", "../../../"].exists(d, file(d + ".tool-versions") && scan(d + ".tool-versions", r'^\s*(java)\s+\S*\d').size() > 0) || ["", "../", "../../", "../../../"].exists(d, ["mise.toml", ".mise.toml", ".config/mise.toml", ".config/mise/config.toml", "mise/config.toml"].exists(n,
file(d + n) && scan(d + n, r'^\s*"?(java)"?\s*=\s*[^#\n]*\d').size() > 0))Fix
Add a Gradle toolchain in the project’s or a parent build (java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }) or a .java-version file.
Agent instruction: Add the stack’s toolchain pin set to the version currently installed; do not upgrade the toolchain in the same change.
See: https://fleetlint.org/baseline/#hygiene, https://fleetlint.org/stacks/, https://fleetlint.org/stacks/#java
Generated by fleetlint docs from catalog v0.2.0.