elastic/elasticsearch · error · IllegalArgumentException

No versions to add or remove specified

Error message

No versions to add or remove specified

What it means

Thrown by UpdateVersionsTask.executeTask() when both addVersion and removeVersion are null. At least one operation is required for the task to do anything.

Source

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

    }

    static String toVersionField(Version version) {
        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;
            }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Pass at least one of --add-version=<version> or --remove-version=<version>.
  2. Audit the release automation to confirm the branch that supplies these options is taken.

Example fix

// before
./gradlew updateVersions

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

Strategy: validation

Validate before calling

// Assert at least one operation is supplied
tasks.named('updateVersions').configure(t -> t.doFirst(spec -> {
    var p = spec.getProviders();
    if (!p.gradleProperty("add-version").forUseAtConfigurationTime().isPresent()
        && !p.gradleProperty("remove-version").forUseAtConfigurationTime().isPresent()) {
        throw new GradleException("--add-version or --remove-version is required");
    }
}));

Prevention

When it happens

Trigger: Invoking updateVersions with neither --add-version nor --remove-version.

Common situations: A release script conditionally supplies the options and supplied none; options were misnamed in CI config.

Related errors


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