From f0d440dfb7927674aa64b8971dc1b18e7003b2be Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 23 Feb 2024 08:39:29 -0800 Subject: [PATCH] =?UTF-8?q?`EnforceBytecodeVersion`=20fails=20with=20"Rest?= =?UTF-8?q?ricted=20to=20JDK=2011=20yet=20[=E2=80=A6]=20contains=20[?= =?UTF-8?q?=E2=80=A6]=20targeted=20to=20JDK=2017"=20(second=20try)=20(#583?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maven/plugins/hpi/ValidateMojo.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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");