diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java index 3dfd7623..d76de831 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java @@ -268,6 +268,12 @@ private void process(Plugin plugin) { } // Run OpenRewrite + if (plugin.getMetadata().getJdks().stream().allMatch(jdk -> jdk.equals(JDK.JAVA_8))) { + LOG.info("Plugin support only Java 8. Need a first compile to general classes"); + plugin.verifyWithoutTests(mavenInvoker, JDK.JAVA_8); + } else { + plugin.withJDK(JDK.min(plugin.getMetadata().getJdks())); + } plugin.runOpenRewrite(mavenInvoker); if (plugin.hasErrors()) { LOG.warn( diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java index 39b7110d..ec872cd5 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java @@ -620,6 +620,7 @@ public void collectMetadata(MavenInvoker maven) { * @param maven The maven invoker instance */ public void runOpenRewrite(MavenInvoker maven) { + withJDK(JDK.JAVA_17); if (config.isFetchMetadataOnly()) { LOG.info("Skipping OpenRewrite recipe application for plugin {} as only metadata is required", name); return; diff --git a/plugin-modernizer-core/src/main/resources/META-INF/rewrite/recipes.yml b/plugin-modernizer-core/src/main/resources/META-INF/rewrite/recipes.yml index 5bae02ec..aa85d32c 100644 --- a/plugin-modernizer-core/src/main/resources/META-INF/rewrite/recipes.yml +++ b/plugin-modernizer-core/src/main/resources/META-INF/rewrite/recipes.yml @@ -414,6 +414,7 @@ recipeList: - io.jenkins.tools.pluginmodernizer.RemoveExtraMavenProperties - io.jenkins.tools.pluginmodernizer.UpgradeBomVersion - io.jenkins.tools.pluginmodernizer.MigrateToJenkinsBaseLineProperty + - org.openrewrite.java.RemoveUnusedImports --- type: specs.openrewrite.org/v1beta/recipe name: io.jenkins.tools.pluginmodernizer.SetupDependabot