gradle/gradle · error · GradleException

Cannot expand %s.

Error message

Cannot expand %s.

What it means

Gradle throws this error when the following condition is violated: Cannot expand <value>.

Source

Thrown at platforms/core-configuration/file-operations/src/main/java/org/gradle/api/internal/file/archive/ZipFileTree.java:113

        decompressionCoordinator.exclusiveAccessTo(expandedDir, () -> {
            AtomicBoolean stopFlag = new AtomicBoolean();
            try (ZipFile zip = ZipFile.builder().setFile(zipFile).get()) {
                // The iteration order of zip.getEntries() is based on the hash of the zip entry. This isn't much use
                // to us. So, collect the entries in a map and iterate over them in alphabetical order.
                Iterator<ZipArchiveEntry> sortedEntries = entriesSortedByName(zip);
                while (!stopFlag.get() && sortedEntries.hasNext()) {
                    ZipArchiveEntry entry = sortedEntries.next();
                    DetailsImpl details = new DetailsImpl(zipFile, expandedDir, entry, zip, stopFlag, chmod);
                    if (entry.isDirectory()) {
                        visitor.visitDir(details);
                    } else {
                        visitor.visitFile(details);
                    }
                }
            } catch (GradleException e) {
                throw e; // Gradle exceptions are already meant to be human-readable, so just rethrow it
            } catch (Exception e) {
                throw new GradleException(format("Cannot expand %s.", getDisplayName()), e);
            }
        });
    }

    private Iterator<ZipArchiveEntry> entriesSortedByName(ZipFile zip) {
        Map<String, ZipArchiveEntry> entriesByName = new TreeMap<>();
        Enumeration<ZipArchiveEntry> entries = zip.getEntries();
        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = entries.nextElement();
            entriesByName.put(entry.getName(), entry);
        }
        return entriesByName.values().iterator();
    }

    @Override
    public Provider<File> getBackingFileProvider() {
        return fileProvider;
    }

View on GitHub (pinned to 534f27719b)

Solutions

  1. Verify the archive file exists and is a valid, non-corrupted archive.
  2. Specify the compression explicitly if the archive extension is misleading.

When it happens

Trigger: Thrown at platforms/core-configuration/file-operations/src/main/java/org/gradle/api/internal/file/archive/ZipFileTree.java:113 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22). Data as JSON: /api/errors/8d3a5d774be22d30. Report an issue: GitHub.