apache/maven · error · ProfileActivationException

Invalid JDK version in profile '{}': {}

Error message

Invalid JDK version in profile '{}': {}

What it means

Thrown while evaluating a profile's <jdk> activation when the value looks like a version range (starts with '[' or '(') but cannot be parsed. JdkPrefixProfileActivator converts '_' to '-' and passes the value to VersionRange.createFromVersionSpec; an InvalidVersionSpecificationException is rethrown as ProfileActivationException naming the offending profile id. Range syntax must be a Maven version range such as [1.8,11) or (,1.8].

Source

Thrown at compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java:45

/**
 * JdkPrefixProfileActivator
 */
@Deprecated
public class JdkPrefixProfileActivator extends DetectedProfileActivator {
    private static final String JDK_VERSION = System.getProperty("java.version");

    @Override
    public boolean isActive(Profile profile) throws ProfileActivationException {
        Activation activation = profile.getActivation();

        String jdk = activation.getJdk();

        // null case is covered by canDetermineActivation(), so we can do a straight startsWith() here.
        if (jdk.startsWith("[") || jdk.startsWith("(")) {
            try {
                return matchJdkVersionRange(jdk);
            } catch (InvalidVersionSpecificationException e) {
                throw new ProfileActivationException(
                        "Invalid JDK version in profile '" + profile.getId() + "': " + e.getMessage());
            }
        }

        boolean reverse = false;

        if (jdk.startsWith("!")) {
            reverse = true;
            jdk = jdk.substring(1);
        }

        if (getJdkVersion().startsWith(jdk)) {
            return !reverse;
        } else {
            return reverse;
        }
    }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Fix the range syntax in the profile: balanced brackets, valid bounds, e.g. <jdk>[1.8,)</jdk>
  2. For a single-version prefix match, drop the brackets entirely: <jdk>17</jdk> matches any 17.x
  3. Run 'mvn help:all-profiles' or validate phase to locate the exact profile id named in the message
  4. Check profiles inherited from parents/BOMs, not just the current POM

Example fix

<!-- before -->
<activation><jdk>[1.8,1.11)</jdk></activation>
<!-- after -->
<activation><jdk>[1.8,1.11)</jdk> is invalid: bounds must parse; use -->
<activation><jdk>[1.8,11)</jdk></activation>
Defensive patterns

Strategy: validation

Validate before calling

// Validate a jdk activation range before relying on the profile
import org.apache.maven.artifact.versioning.VersionRange;
try {
    VersionRange.createFromVersionSpec(jdk.replace('_','-'));
} catch (Exception invalid) {
    throw new IllegalArgumentException("Bad <jdk> activation: " + jdk, invalid);
}

Prevention

When it happens

Trigger: A POM profile with activation <jdk>[something-invalid</jdk>: unbalanced brackets, empty bounds like [,1.8], non-numeric bounds, or a malformed range such as [1.8,1.9]x. Activation is only attempted when canDetectActivation() sees a non-empty jdk element.

Common situations: Hand-edited POMs with typos in the jdk range; copying a single-version spec into range syntax (e.g. '[17.]' or '[17'); CI building the project for the first time so the previously inactive profile is evaluated; profiles inherited from parent BOMs with legacy 1.8_u40-style strings.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/42f3b74408edc16b. Report an issue: GitHub.