elastic/elasticsearch · error · IllegalArgumentException

No new version added to set as the current version

Error message

No new version added to set as the current version

What it means

Thrown by UpdateVersionsTask.executeTask() when --set-current was requested but addVersion is null. CURRENT can only be repointed to a newly added version, so the combination is invalid.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateVersionsTask.java:94

        return String.format("V_%d_%d_%d", version.getMajor(), version.getMinor(), version.getRevision());
    }

    static Optional<Version> parseVersionField(CharSequence field) {
        Matcher m = VERSION_FIELD.matcher(field);
        if (m.find() == false) return Optional.empty();

        return Optional.of(
            new Version(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)), m.group(4))
        );
    }

    @TaskAction
    public void executeTask() throws IOException {
        if (addVersion == null && removeVersion == null) {
            throw new IllegalArgumentException("No versions to add or remove specified");
        }
        if (setCurrent && addVersion == null) {
            throw new IllegalArgumentException("No new version added to set as the current version");
        }
        if (addVersion != null && removeVersion != null && Objects.equals(addVersion, removeVersion)) {
            throw new IllegalArgumentException("Same version specified to add and remove");
        }

        Path versionJava = rootDir.resolve(VERSION_FILE_PATH);
        CompilationUnit file = LexicalPreservingPrinter.setup(StaticJavaParser.parse(versionJava));

        Optional<CompilationUnit> modifiedFile = Optional.empty();
        if (addVersion != null) {
            LOGGER.lifecycle("Adding new version [{}] to [{}]", addVersion, versionJava);
            var added = addVersionConstant(modifiedFile.orElse(file), addVersion, setCurrent);
            if (added.isPresent()) {
                modifiedFile = added;
            }
        }
        if (removeVersion != null) {
            LOGGER.lifecycle("Removing version [{}] from [{}]", removeVersion, versionJava);

View on GitHub (pinned to db6a809a66)

Solutions

  1. Always pair --set-current with an --add-version, e.g. --add-version=8.10.0 --set-current.
  2. If you only meant to remove a version, drop --set-current.

Example fix

// before
./gradlew updateVersions --set-current

// after
./gradlew updateVersions --add-version=8.10.0 --set-current
Defensive patterns

Strategy: validation

Validate before calling

// Enforce the --set-current + --add-version contract up front
boolean setCurrent = providers.gradleProperty("set-current").isPresent();
boolean hasAdd = providers.gradleProperty("add-version").isPresent();
if (setCurrent && !hasAdd) {
    throw new GradleException("--set-current requires --add-version");
}

Prevention

When it happens

Trigger: Passing --set-current together with only --remove-version, or with no --add-version at all.

Common situations: Operator copies a command template and forgets the --add-version while keeping --set-current; CI flag wiring dropped --add-version.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/7087f8e21a8b0cf4. Report an issue: GitHub.