Skip to content

Guardrails / java

Java version is reproducible ​

java/version-reproducible@v1

The Java release is declared through a mechanism that provisions the JDK, not one that asks the running JDK to target an older release.

Idjava/version-reproducible
Versionv1
Categoryjava
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsjava

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.

CollectorGathersInputs it is given
javaThe 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 ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "java/version-reproducible@v1",
              "severity": "warning",
              "with": {
                  "projectDir": "."
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

How to fix ​

Replace sourceCompatibility, targetCompatibility, options.release or maven.compiler.release with a toolchain. A toolchain selects the JDK itself, instead of asking the running one to target an older release:

kotlin
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(21))
    }
}

With sourceCompatibility = JavaVersion.VERSION_17, the build still compiles against the class library of whichever JDK is on the runner. A method added after Java 17 resolves at compile time, then throws NoSuchMethodError on the Java 17 runtime the artifact was built for.

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-declared. The build declares the Java release it compiles for, and that release is no older than the configured floor.

All 3 java guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412