diff --git a/src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateMojo.java b/src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateMojo.java index cf3ec9c8f6..7107a2c93d 100644 --- a/src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateMojo.java +++ b/src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateMojo.java @@ -42,8 +42,20 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Java " + javaVersion + " or later is necessary to build this plugin."); } writeProfileMarker(javaVersion); - setProperty("maven.compiler.release", Integer.toString(javaVersion.toReleaseVersion())); - setProperty("maven.compiler.testRelease", Integer.toString(javaVersion.toReleaseVersion())); + if (!project.getProperties() + .getProperty("maven.compiler.release") + .equals(Integer.toString(javaVersion.toReleaseVersion()))) { + // Apply the profile to the in-memory model. + setProperty("maven.compiler.release", Integer.toString(javaVersion.toReleaseVersion())); + setProperty("maven.compiler.testRelease", Integer.toString(javaVersion.toReleaseVersion())); + + // Unfortunately, I see no way to update the Enforcer configuration without restarting Maven. + // In the meantime, skip this rule in the current invocation to avoid a false positive. + if (!project.getProperties().containsKey("enforcer.skipRules")) { + getLog().warn("Skipping enforceBytecodeVersion; will run on next invocation."); + project.getProperties().setProperty("enforcer.skipRules", "enforceBytecodeVersion"); + } + } if (new VersionNumber(findJenkinsVersion()).compareTo(new VersionNumber("2.361")) < 0) { throw new MojoExecutionException("This version of maven-hpi-plugin requires Jenkins 2.361 or later");