apache/maven · error · IllegalStateException
Could not parse current Java version
Error message
Could not parse current Java version
What it means
MavenPluginJavaPrerequisiteChecker.matchesVersion validates a plugin descriptor's requiredJavaVersion against the running JVM. The required side is parsed as a VersionConstraint; the current side is System.getProperty("java.version") parsed with Resolver's GenericVersionScheme. If that property value is null, blank, or otherwise unparseable, Maven cannot even form the comparison and throws IllegalStateException.
Source
Thrown at impl/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java:65
if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) {
throw new IllegalStateException("Required Java version " + requiredJavaVersion
+ " is not met by current version: " + currentJavaVersion);
}
}
}
boolean matchesVersion(String requiredVersion, String currentVersion) {
VersionConstraint constraint;
try {
constraint = versionScheme.parseVersionConstraint(requiredVersion);
} catch (InvalidVersionSpecificationException e) {
throw new IllegalArgumentException("Invalid 'requiredJavaVersion' given in plugin descriptor", e);
}
Version current;
try {
current = versionScheme.parseVersion(currentVersion);
} catch (InvalidVersionSpecificationException e) {
throw new IllegalStateException("Could not parse current Java version", e);
}
if (constraint.getRange() == null) {
return constraint.getVersion().compareTo(current) <= 0;
}
return constraint.containsVersion(current);
}
}
View on GitHub (pinned to e4093d4e12)
Solutions
- Print the actual value with `mvn -version` and `java -version`; confirm the JVM reports a standard version string.
- Remove any -Djava.version=... override from MAVEN_OPTS, CI environment, or launcher scripts and let the JVM report its own value.
- Switch to a mainstream JDK distribution whose java.version follows the standard scheme.
- Pin an older version of the offending plugin that does not declare requiredJavaVersion, or rebuild the plugin with a corrected/simplified value.
Example fix
# before: launcher forces a nonstandard value mvn -Djava.version="17.0.1 custom build" clean # after: let the JVM report its own version mvn clean
Defensive patterns
Strategy: validation
Validate before calling
String v = System.getProperty("java.version");
if (v == null || v.isBlank() || !v.matches("[0-9]+(\\.[0-9]+){0,3}([-._+].*)?")) {
throw new IllegalStateException("java.version is not a parseable version string: " + v);
} Try / catch
try {
pluginManager.checkPrerequisites(descriptor);
} catch (IllegalStateException e) {
if (e.getCause() instanceof org.eclipse.aether.version.InvalidVersionSpecificationException ives) {
// environment problem, not a plugin choice problem: fix the JVM/launcher
}
throw e;
} Prevention
- Never pass -Djava.version on the Maven command line; it shadows the JVM-reported value
- Pin the JDK in CI to a standard distribution so java.version is well-formed
- In launcher/embedder code, whitelist system properties forwarded to the Maven process
When it happens
Trigger: Executing a plugin whose descriptor declares requiredJavaVersion (set via maven-plugin-plugin from the plugin POM) while the JVM's java.version system property has a value the GenericVersionScheme rejects: null, empty, or an exotic nonstandard string. Reached from MavenPluginPrerequisitesChecker.accept during plugin loading/prerequisite checks.
Common situations: Launcher scripts or tests that override -Djava.version with a nonstandard value; stripped-down/custom JVM distributions reporting unusual version strings; embedding Maven in a process where system properties were sanitized before the build starts.
Related errors
- Required Maven version {} is not met by current version {}
- Unable to read Maven version from maven-core
- Cannot find permitted subclass '{}' for sealed type {}
- Cannot inline property {}
- A required class was missing while executing {}: {}
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/7336e6acd988d9a6.
Report an issue: GitHub.