From de5fd767d45633dd2a77885671d7a0c4254168a3 Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Thu, 17 Nov 2022 11:31:58 +0100 Subject: [PATCH] Suppress warning for mvn+kapt+jdk9 Suppress the warning about lack of tools.jar, as this jar does not present in JDK9+ #KT-47110 Fixed --- .../maven/kapt/KaptJVMCompilerMojo.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java index d91df119d41..6cfdf53eec1 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/kapt/KaptJVMCompilerMojo.java @@ -40,7 +40,9 @@ import java.util.stream.Collectors; import static org.jetbrains.kotlin.maven.Util.joinArrays; import static org.jetbrains.kotlin.maven.kapt.AnnotationProcessingManager.*; -/** @noinspection UnusedDeclaration */ +/** + * @noinspection UnusedDeclaration + */ @Mojo(name = "kapt", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) public class KaptJVMCompilerMojo extends K2JVMCompileMojo { @Parameter @@ -72,7 +74,7 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo { @Component private ArtifactHandlerManager artifactHandlerManager; - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) private MavenSession session; @Component @@ -194,8 +196,7 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo { try { resolvedArtifacts = getAnnotationProcessingManager().resolveAnnotationProcessors(annotationProcessorPaths); - } - catch (Exception e) { + } catch (Exception e) { throw new MojoExecutionException("Error while processing kapt options", e); } @@ -220,6 +221,18 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo { getLog().warn("Can't determine Java home, 'java.home' property does not exist"); return null; } + + String jdkStringVersion = System.getProperty("java.specification.version"); + if (jdkStringVersion == null) return null; + int jdkVersion; + try { + jdkVersion = Integer.parseInt(jdkStringVersion); + } catch (NumberFormatException e) { + // we got 1.8 or 1.6 + jdkVersion = 0; + } + if (jdkVersion >= 9) return null; + File javaHome = new File(javaHomePath); File toolsJar = new File(javaHome, "lib/tools.jar"); if (toolsJar.exists()) { @@ -302,8 +315,7 @@ public class KaptJVMCompilerMojo extends K2JVMCompileMojo { int equalsIndex = option.indexOf("="); if (equalsIndex < 0) { map.put(option, ""); - } - else { + } else { map.put(option.substring(0, equalsIndex).trim(), option.substring(equalsIndex + 1).trim()); } }