scijava / jgo

Launch Java code from the CLI, installation-free. ☕
https://pypi.org/project/jgo/
The Unlicense
78 stars 16 forks source link

Running the kotlin compiler #89

Open jayvdb opened 1 year ago

jayvdb commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 9 months ago

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.