diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java index 33f4408d196..33f5968b5f7 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,10 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { @Argument(value = "include-runtime", description = "Include Kotlin runtime in to resulting .jar") public boolean includeRuntime; + @Argument(value = "jdk", description = "Path to JDK home to include into classpath, if differs from default %JAVA_HOME%") + @ValueDescription("") + public String jdk; + @Argument(value = "no-jdk", description = "Don't include Java runtime into classpath") public boolean noJdk; diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 7635bc3a5e4..d4e5bf4283a 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -62,7 +62,19 @@ class K2JVMCompiler : CLICompiler() { try { if (!arguments.noJdk) { - configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) + if (arguments.jdk != null) { + configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots(File(arguments.jdk))) + } + else { + configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) + } + } + else { + if (arguments.jdk != null) { + messageCollector.report(CompilerMessageSeverity.WARNING, + "The '-jdk' option with a path to JDK is ignored because '-no-jdk' is specified", + CompilerMessageLocation.NO_LOCATION) + } } } catch (t: Throwable) { diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index ef9b7d16c26..b802088cd82 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -3,6 +3,7 @@ where possible options include: -d Destination for generated class files -classpath (-cp) Paths where to find user class files -include-runtime Include Kotlin runtime in to resulting .jar + -jdk Path to JDK home to include into classpath, if differs from default %JAVA_HOME% -no-jdk Don't include Java runtime into classpath -no-stdlib Don't include Kotlin runtime into classpath -module Path to the module file to compile diff --git a/compiler/testData/cli/jvm/wrongArgument.out b/compiler/testData/cli/jvm/wrongArgument.out index 78663953d81..4ba88fde362 100644 --- a/compiler/testData/cli/jvm/wrongArgument.out +++ b/compiler/testData/cli/jvm/wrongArgument.out @@ -4,6 +4,7 @@ where possible options include: -d Destination for generated class files -classpath (-cp) Paths where to find user class files -include-runtime Include Kotlin runtime in to resulting .jar + -jdk Path to JDK home to include into classpath, if differs from default %JAVA_HOME% -no-jdk Don't include Java runtime into classpath -no-stdlib Don't include Kotlin runtime into classpath -module Path to the module file to compile diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java index a8e99ade2da..a8559d003d0 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -144,4 +144,9 @@ public class PathUtil { public static List getJdkClassesRoots() { return JavaSdkUtil.getJdkClassesRoots(new File(System.getProperty("java.home")), true); } + + @NotNull + public static List getJdkClassesRoots(@NotNull File jdkHome) { + return JavaSdkUtil.getJdkClassesRoots(jdkHome, false); + } } diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 0b99a0075d6..bc135dc3ddc 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -195,6 +195,7 @@ open class KotlinCompile() : AbstractKotlinCompile() { logger.kotlinDebug("args.pluginOptions = ${args.pluginOptions.joinToString(File.pathSeparator)}") args.noStdlib = true + args.jdk = kotlinOptions.jdk args.noJdk = kotlinOptions.noJdk args.noInline = kotlinOptions.noInline args.noOptimize = kotlinOptions.noOptimize diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java index ab1afc54c6f..76a9c7e0efd 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JVMCompileMojo.java @@ -16,11 +16,7 @@ package org.jetbrains.kotlin.maven; -import kotlin.collections.CollectionsKt; -import kotlin.jvm.functions.Function1; -import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -30,7 +26,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; import java.io.File; -import java.util.ArrayList; import java.util.List; import static com.intellij.openapi.util.text.StringUtil.join; @@ -67,6 +62,9 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase