jgo icon indicating copy to clipboard operation
jgo copied to clipboard

Running the kotlin compiler

Open jayvdb opened this issue 2 years ago • 3 comments

The following doesn't work, because there is no (predictable) value which can be used to populate the -kotlin-home cli arg. Is there a way we can make this possible ? Some CLI arg substitution that can occur within jgo?

$ jgo --additional-endpoints org.jetbrains.kotlin:kotlin-stdlib org.jetbrains.kotlin:kotlin-compiler Foo.kt
INFO 2023-02-11 15:01:26,477: First time start-up may be slow. Downloaded dependencies will be cached for shorter start-up times in subsequent executions.
INFO 2023-02-11 15:01:28,947: Inferring main class from jar manifest
INFO 2023-02-11 15:01:29,021: Inferred main class: org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
warning: unable to find kotlin-stdlib.jar in the Kotlin home directory. Pass either '-no-stdlib' to prevent adding it to the classpath, or the correct '-kotlin-home'
warning: unable to find kotlin-script-runtime.jar in the Kotlin home directory. Pass either '-no-stdlib' to prevent adding it to the classpath, or the correct '-kotlin-home'
warning: unable to find kotlin-reflect.jar in the Kotlin home directory. Pass either '-no-reflect' or '-no-stdlib' to prevent adding it to the classpath, or the correct '-kotlin-home'
Foo.kt:8:17: error: cannot access built-in declaration 'kotlin.Int'. Ensure that you have a dependency on the Kotlin standard library
fun indexing(): Int {
                ^

jayvdb avatar Feb 11 '23 07:02 jayvdb

fwiw, I also have the same problem with https://github.com/kscripting/kscript

$ jgo --additional-endpoints commons-cli:commons-cli org.jetbrains.kotlin:kotlin-scripting-jvm org.jetbrains.kotlin:kotlin-stdlib io.github.kscripting:shell io.github.kscripting:kscript:io.github.kscripting.kscript.KscriptKt linux Foo.kt
[kscript] [ERROR] KOTLIN_HOME is not set and could not be inferred from context.

jayvdb avatar Feb 11 '23 07:02 jayvdb

Quite interestingly, using kotlin-compiler-embeddable also fails

> jgo --additional-endpoints org.jetbrains.kotlin:kotlin-stdlib org.jetbrains.kotlin:kotlin-compiler-embeddable:org.jetbrains.kotlin.cli.jvm.K2JVMCompiler path/to/script.kt 
warning: unable to find kotlin-stdlib.jar in the Kotlin home directory. Pass either '-no-stdlib' to prevent adding it to the classpath, or the correct '-kotlin-home'
...

jayvdb avatar Feb 18 '23 06:02 jayvdb

kscript now works with KOTLIN_HOME set

jgo --additional-endpoints commons-cli:commons-cli commons-codec:commons-codec io.github.kscripting:shell io.github.kscripting:kscript:io.github.kscripting.kscript.KscriptKt linux tests/expected/print.kt

otherwise the error is

[kscript] [ERROR] KOTLIN_HOME is not set and could not be inferred from context.

jayvdb avatar Dec 30 '23 22:12 jayvdb