diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java
index ae946c6fefe..1d2f6786a7d 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java
@@ -49,6 +49,10 @@ import static org.jetbrains.kotlin.cli.common.environment.UtilKt.setIdeaIoUseFal
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
public abstract class CLICompiler extends CLITool {
+
+ public static String KOTLIN_HOME_PROPERTY = "kotlin.home";
+ public static String KOTLIN_HOME_ENV_VAR = "KOTLIN_HOME";
+
// Used in CompilerRunnerUtil#invokeExecMethod, in Eclipse plugin (KotlinCLICompiler) and in kotlin-gradle-plugin (GradleCompilerRunner)
@NotNull
public ExitCode execAndOutputXml(@NotNull PrintStream errStream, @NotNull Services services, @NotNull String... args) {
@@ -210,8 +214,14 @@ public abstract class CLICompiler extends CLI
@Nullable
private static KotlinPaths computeKotlinPaths(@NotNull MessageCollector messageCollector, @NotNull CommonCompilerArguments arguments) {
KotlinPaths paths;
- if (arguments.getKotlinHome() != null) {
- File kotlinHome = new File(arguments.getKotlinHome());
+ String kotlinHomeProperty = System.getProperty(KOTLIN_HOME_PROPERTY);
+ String kotlinHomeEnvVar = System.getenv(KOTLIN_HOME_ENV_VAR);
+ File kotlinHome =
+ arguments.getKotlinHome() != null ? new File(arguments.getKotlinHome()) :
+ kotlinHomeProperty != null ? new File(kotlinHomeProperty) :
+ kotlinHomeEnvVar != null ? new File(kotlinHomeEnvVar)
+ : null;
+ if (kotlinHome != null) {
if (kotlinHome.isDirectory()) {
paths = new KotlinPathsFromHomeDir(kotlinHome);
}