Skip to content

Commit f0d440d

Browse files
authored
EnforceBytecodeVersion fails with "Restricted to JDK 11 yet […] contains […] targeted to JDK 17" (second try) (#583)
1 parent e47a848 commit f0d440d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateMojo.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,20 @@ public void execute() throws MojoExecutionException {
4242
throw new MojoExecutionException("Java " + javaVersion + " or later is necessary to build this plugin.");
4343
}
4444
writeProfileMarker(javaVersion);
45-
setProperty("maven.compiler.release", Integer.toString(javaVersion.toReleaseVersion()));
46-
setProperty("maven.compiler.testRelease", Integer.toString(javaVersion.toReleaseVersion()));
45+
if (!project.getProperties()
46+
.getProperty("maven.compiler.release")
47+
.equals(Integer.toString(javaVersion.toReleaseVersion()))) {
48+
// Apply the profile to the in-memory model.
49+
setProperty("maven.compiler.release", Integer.toString(javaVersion.toReleaseVersion()));
50+
setProperty("maven.compiler.testRelease", Integer.toString(javaVersion.toReleaseVersion()));
51+
52+
// Unfortunately, I see no way to update the Enforcer configuration without restarting Maven.
53+
// In the meantime, skip this rule in the current invocation to avoid a false positive.
54+
if (!project.getProperties().containsKey("enforcer.skipRules")) {
55+
getLog().warn("Skipping enforceBytecodeVersion; will run on next invocation.");
56+
project.getProperties().setProperty("enforcer.skipRules", "enforceBytecodeVersion");
57+
}
58+
}
4759

4860
if (new VersionNumber(findJenkinsVersion()).compareTo(new VersionNumber("2.361")) < 0) {
4961
throw new MojoExecutionException("This version of maven-hpi-plugin requires Jenkins 2.361 or later");

0 commit comments

Comments
 (0)