Skip to content

Commit

Permalink
Suppress warning for mvn+kapt+jdk9
Browse files Browse the repository at this point in the history
Suppress the warning about lack of tools.jar, as this jar does not present in JDK9+

#KT-47110 Fixed
  • Loading branch information
Aleksei.Cherepanov authored and teamcity committed Nov 21, 2022
1 parent f2bc25c commit de5fd76
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -194,8 +196,7 @@ protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArgument

try {
resolvedArtifacts = getAnnotationProcessingManager().resolveAnnotationProcessors(annotationProcessorPaths);
}
catch (Exception e) {
} catch (Exception e) {
throw new MojoExecutionException("Error while processing kapt options", e);
}

Expand All @@ -220,6 +221,18 @@ private String getJdkToolsJarPath() {
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()) {
Expand Down Expand Up @@ -302,8 +315,7 @@ private static Map<String, String> parseOptionList(@Nullable List<String> rawOpt
int equalsIndex = option.indexOf("=");
if (equalsIndex < 0) {
map.put(option, "");
}
else {
} else {
map.put(option.substring(0, equalsIndex).trim(), option.substring(equalsIndex + 1).trim());
}
}
Expand Down

0 comments on commit de5fd76

Please sign in to comment.