Java version is declared
java/version-declared@v1
The build declares the Java release it compiles for, and that release is no older than the configured floor.
| Id | java/version-declared |
| Version | v1 |
| Category | java |
| Default severity | warning |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | java |
Collectors
This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.
| Collector | Gathers | Inputs it is given |
|---|---|---|
java | The Java version the Gradle or Maven build declares, how it declares it, and whether that mechanism makes the build reproducible, for the project and for every Gradle project it includes. | projectDir |
The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.
Configuration
{
"guardrails": {
"failOn": "error",
"checks": [
{
"use": "java/version-declared@v1",
"severity": "warning",
"with": {
"projectDir": ".",
"minVersion": "17"
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
projectDir | Directory holding the project, relative to the directory the CLI runs in. | . | GUARDRAIL_INPUT_PROJECTDIR |
minVersion | Oldest Java release accepted, as a release number such as 17. A declared release below this is a violation. | 17 | GUARDRAIL_INPUT_MINVERSION |
How to fix
Declare the release where the build already configures itself:
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}In Maven, set <maven.compiler.release>21</maven.compiler.release>. With nothing declared, the build compiles for whatever release the runner's JDK defaults to. An API call from a newer release then compiles on the machine where it was added and breaks on an agent with an older JDK.
More in java
java/toolchain-declared. The build selects the JDK it compiles with through a Java toolchain, instead of using whichever JDK launched it.java/version-reproducible. The Java release is declared through a mechanism that provisions the JDK, not one that asks the running JDK to target an older release.