Why does kotlinc need the path to installation path? And what's minimum jar files are required to compile kotlin codes?


#1

I echoed the commands that are executed in kotlinc:

[xxxxxxx@uss intro1]$ bash -x ~/Downloads/kotlinc/bin/kotlinc AimToTen.kt
+ cygwin=false
+ case "`uname`" in
++ uname
++ findKotlinHome
++ local source=/users/1/xxxxxxx/Downloads/kotlinc/bin/kotlinc
++ '[' -h /users/1/xxxxxxx/Downloads/kotlinc/bin/kotlinc ']'
+++ dirname /users/1/xxxxxxx/Downloads/kotlinc/bin/kotlinc
++ cd -P /users/1/xxxxxxx/Downloads/kotlinc/bin/..
++ pwd
+ KOTLIN_HOME=/users/1/xxxxxxx/Downloads/kotlinc
+ false
+ '[' -n '' ']'
+ JAVA_OPTS='-Xmx256M -Xms32M'
+ declare -a java_args
+ declare -a kotlin_args
+ '[' 1 -gt 0 ']'
+ case "$1" in
+ kotlin_args=("${kotlin_args[@]}" "$1")
+ shift
+ '[' 0 -gt 0 ']'
+ '[' -z '' -a -n '' -a -x /bin/java ']'
+ declare -a kotlin_app
+ '[' -n '' ']'
+ '[' -n '' ']'
+ KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
+ java_args=("${java_args[@]}" "-noverify")
+ kotlin_app=("${KOTLIN_HOME}/lib/kotlin-preloader.jar" "org.jetbrains.kotlin.preloading.Preloader" "-cp" "${KOTLIN_HOME}/lib/kotlin-compiler.jar" $KOTLIN_COMPILER)
+ java -Xmx256M -Xms32M -noverify -cp /users/1/xxxxxxx/Downloads/kotlinc/lib/kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp /users/1/xxxxxxx/Downloads/kotlinc/lib/kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler AimToTen.kt

As you can see in the last line, there is a path to the installation path of kotlinc. I want to remove them, but failed. Here are some attempts:

failed:
java -Xmx256M -Xms32M -noverify -cp kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler AimToTen.kt

ok:
java -Xmx256M -Xms32M -noverify -cp /users/1/xxxxxxx/Downloads/kotlinc/lib/kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp /users/1/xxxxxxx/Downloads/kotlinc/lib/kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler AimToTen.kt

ok:
java -Xmx256M -Xms32M -noverify -cp kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp /users/1/xxxxxxx/Downloads/kotlinc/lib/kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler AimToTen.kt

ok maybe, because AimToTen.class was generated and could be called:
[xxxxxxx@uss intro1]$ java -Xmx256M -Xms32M -noverify -cp kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -cp kotlin-runtime.jar AimToTen.kt
warning: classpath entry points to a non-existent location: /users/1/xxxxxxx/Codes/lib/kotlin-runtime.jar

The last line does not use any path to installation directory. But it echoes an warning :frowning:

However the .class file is generated, which means .kt file was compiled successfully(?).

But why it shows a warning? And are kotlin-preloader.jar, kotlin-compiler.jar, kotlin-reflect.jar and kotlin-runtime.jar the minimum requirements for compiling .kt files?

P.S. I want to run class by java -jar ".:kotlin-runtime.jar" <ClassName>.


#2

Sorry, I don’t quite understand: what are you trying to accomplish?


#3

Sorry for that. I want to figure out: why there is a warning in my last attempt.

[xxxxxxx@uss intro1]$ java -Xmx256M -Xms32M -noverify -cp kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader -cp kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -cp kotlin-runtime.jar AimToTen.kt
warning: classpath entry points to a non-existent location: /users/1/xxxxxxx/Codes/lib/kotlin-runtime.jar

#4

Why are you making any attempts at all? Why can’t you simply use the script as is?


#5

Sorry to jump an old thread. I am working on the Facebook Buck Build integration for Kotlin, invoking the K2JVMCompiler directly from Java, and I too would like to know what the minimum JARs required to compile with Kotlin are.

I haven’t tried all of the various permutations, which I can of course, but an official answer would save me some time.

In the 1.1.2-2 installation, I find these jars:

allopen-compiler-plugin.jar
android-extensions-compiler.jar
kotlin-annotation-processing.jar
kotlin-ant.jar
kotlin-build-common-test.jar
kotlin-compiler-client-embeddable.jar
kotlin-compiler.jar
kotlin-daemon-client.jar
kotlin-jslib-sources.jar
kotlin-jslib.jar
kotlin-preloader.jar
kotlin-reflect.jar
kotlin-runner.jar
kotlin-runtime-sources.jar
kotlin-runtime.jar
kotlin-script-runtime-sources.jar
kotlin-script-runtime.jar
kotlin-stdlib-js-sources.jar
kotlin-stdlib-js.jar
kotlin-stdlib-sources.jar
kotlin-stdlib.jar
kotlin-test-js.jar
kotlin-test.jar
noarg-compiler-plugin.jar
sam-with-receiver-compiler-plugin.jar
source-sections-compiler-plugin.jar

Some of them are clearly irrelavent to our use, for example kotlin-ant.jar, but others are less clear.

The use-case here is that Buck users, for the purposes of compilation, want to either 1) depend on specific versions of these JARs from Maven, or 2) commit specific versions of these JARs into their repository, in order to guarantee a portable and reproducible build.

Currently, the Buck prototype code for in-memory compilation is emitting these two warnings with only kotlin-compiler and kotlin-stdlib-jdk8 in the classpath:

warning: classpath entry points to a non-existent location: <no_path>/lib/kotlin-script-runtime.jar
warning: classpath entry points to a non-existent location: <no_path>/lib/kotlin-reflect.jar

Regards,
Brett Wooldridge


#6

Then you should pass the path to those jars with the -cp and also specify -no-stdlib parameter to disable providing the standard library bundled in the kotlin compiler distribution.