diff --git a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt index 674166fd032..6a26df13645 100644 --- a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt +++ b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ant import org.apache.tools.ant.types.Path import org.apache.tools.ant.types.Reference -import java.io.File import java.io.File.pathSeparator public class Kotlin2JvmTask : KotlinCompilerBaseTask() { @@ -60,18 +59,11 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() { args.add("-d") args.add(output!!.canonicalPath) - val classpath = arrayListOf() - compileClasspath?.let { classpath.addAll(it.list()) } - src!!.list().forEach { - val file = File(it) - if (file.isDirectory() || file.extension != "kt") { - classpath.add(it) - } + compileClasspath?.let { + args.add("-classpath") + args.add(it.list().join(pathSeparator)) } - args.add("-classpath") - args.add(classpath.join(pathSeparator)) - externalAnnotations?.let { args.add("-annotations") args.add(it.list().join(pathSeparator)) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.java index c77fc72af99..d2f2a7c665e 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.java @@ -81,25 +81,16 @@ public class K2JVMCompiler extends CLICompiler { } try { - configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments)); - configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments)); + if (!arguments.noJdk) { + configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots()); + } } catch (Throwable t) { MessageCollectorUtil.reportException(messageCollector, t); return INTERNAL_ERROR; } - if (!arguments.script && - arguments.module == null && - arguments.freeArgs.isEmpty() && - !arguments.version - ) { - ReplFromTerminal.run(rootDisposable, configuration); - return ExitCode.OK; - } - else if (arguments.module != null) { - } - else if (arguments.script) { + if (arguments.script) { if (arguments.freeArgs.isEmpty()) { messageCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate", CompilerMessageLocation.NO_LOCATION); @@ -107,8 +98,24 @@ public class K2JVMCompiler extends CLICompiler { } configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs.get(0)); } - else { + else if (arguments.module == null) { CompileEnvironmentUtil.addSourceFilesCheckingForDuplicates(configuration, arguments.freeArgs); + + // Adding all directory sources to classpath to resolve Java symbols from Kotlin + for (String source : arguments.freeArgs) { + File file = new File(source); + if (file.isDirectory()) { + configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, file); + } + } + } + + configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(paths, arguments)); + configuration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, getAnnotationsPath(paths, arguments)); + + if (arguments.module == null && arguments.freeArgs.isEmpty() && !arguments.version) { + ReplFromTerminal.run(rootDisposable, configuration); + return ExitCode.OK; } configuration.put(JVMConfigurationKeys.SCRIPT_PARAMETERS, arguments.script @@ -191,9 +198,6 @@ public class K2JVMCompiler extends CLICompiler { @NotNull private static List getClasspath(@NotNull KotlinPaths paths, @NotNull K2JVMCompilerArguments arguments) { List classpath = Lists.newArrayList(); - if (!arguments.noJdk) { - classpath.addAll(PathUtil.getJdkClassesRoots()); - } if (arguments.classpath != null) { for (String element : Splitter.on(File.pathSeparatorChar).split(arguments.classpath)) { classpath.add(new File(element)); 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 49f36d45b2c..f98e563db2e 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 @@ -98,24 +98,17 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase classpathList = new ArrayList(); - if (module != null) { LOG.info("Compiling Kotlin module " + module); arguments.module = module; } - else { - // TODO: Move it compiler - classpathList.addAll(getSources()); - } - - classpathList.addAll(classpath); + ArrayList classpathList = new ArrayList(classpath); if (classpathList.remove(output)) { LOG.debug("Removed target directory from compiler classpath (" + output + ")"); } - if (classpathList.size() > 0) { + if (!classpathList.isEmpty()) { String classPathString = join(classpathList, File.pathSeparator); LOG.info("Classpath: " + classPathString); arguments.classpath = classPathString;