SonarSource/sonarqube · error · GradleException

JRE files in ${jresDir} do not match jres-metadata.json (mis

Error message

JRE files in ${jresDir} do not match jres-metadata.json (missing: ${missing}, unexpected: ${extra}). Run './gradlew clean' to remove stale JREs, then rebuild.

What it means

The distribution build validates that downloaded JRE files under the jres directory exactly match jres-metadata.json. If files are missing or unexpected extras exist, in CI (env CI=true) it throws this GradleException; locally it only logs a warning so leftover .DS_Store files or partial downloads don't abort builds.

Source

Thrown at sonar-application/build.gradle:490

  mustRunAfter cyclonedxBom
  doLast {
    // Check for stale JREs: the jres directory should contain exactly as many files as jres-metadata.json.
    // Extra files from a previous JRE version inflate the zip and can cause the size check below to fail.
    // Fix: run './gradlew clean' to remove stale JREs, then rebuild.
    // Match files by name against metadata instead of raw count to tolerate unrelated entries (.DS_Store, partial downloads, etc.)
    def jresDir = layout.buildDirectory.dir('jres').get().asFile
    def jresMetadata = new JsonSlurper().parse(file(layout.projectDirectory.dir('src/main/resources/jres-metadata.json').asFile))
    def expectedNames = jresMetadata.collect { it.filename } as Set
    def actualNames = (jresDir.listFiles()?.collect { it.name } ?: []) as Set
    def missing = expectedNames - actualNames
    def extra = actualNames - expectedNames
    if (missing || extra) {
      def message =
        "JRE files in ${jresDir} do not match jres-metadata.json (missing: ${missing}, unexpected: ${extra}). " +
          "Run './gradlew clean' to remove stale JREs, then rebuild."
      // Strict in CI; warn locally so leftover .DS_Store / partial downloads don't abort local builds.
      if (System.getenv("CI") == "true") {
        throw new GradleException(message)
      }
      logger.warn(message)
    }

    // When the archive size increases due to dependencies, the expected size should be updated as well.
    // Unknown failures may cause the archive size to shrink accidentally in size.
    //
    // This check is in place as a protection so that the developer checks why the size increased or decreased
    // out of this expected area.
    //
    // If the change is expected, modify the expectedSize to be whatever the archiveSize is rounded down to the nearest 10MB.
    // The calculation below will also tell you the number you should use here.
    // If this is not expected, try performing a Gradle clean and refreshing dependencies.
    // Non-release builds skip re-compressing already-compressed entries (see skipAlreadyCompressed above), which
    // trades a larger archive for a much faster build; release builds fully compress, staying close to the old size.
    def expectedSize = release ? 940_000_000 : 990_000_000
    // We set a tolerance to avoid failing the build for small differences in the archive size.
    def tolerance = 15_000_000

View on GitHub (pinned to 184c821202)

Solutions

  1. Run './gradlew clean' then rebuild to remove stale/partial JREs
  2. Manually delete the jres directory contents and re-run the build so files re-download per metadata
  3. If a legitimately new file is flagged, update jres-metadata.json to include it

Example fix

// before
./gradlew assemble
// after
./gradlew clean assemble
Defensive patterns

Strategy: validation

Validate before calling

// shell: ensure jres dir matches metadata before CI build
# after a failed build or branch switch:
./gradlew clean

Prevention

When it happens

Trigger: A previous interrupted build left partial JRE downloads; OS noise files (e.g. .DS_Store) in jresDir; metadata updated without cleaning, leaving stale JRE files not listed in jres-metadata.json; running the zip task in CI with a dirty workspace.

Common situations: Retrying a failed download that half-completed; switching branches where jres-metadata.json changed; macOS developer artifacts checked into the directory.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/10570e24ac489b23. Report an issue: GitHub.