Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnforceBytecodeVersion fails with "Restricted to JDK 11 yet […] contains […] targeted to JDK 17" (second try) #583

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down