kscript icon indicating copy to clipboard operation
kscript copied to clipboard

kotlinc can't find Java when invoked via kscript (Cygwin)

Open seanf opened this issue 5 years ago • 10 comments

When kscript runs kotlinc, somehow it can't find java. Java, Kotlin and kscript are all installed via SDKMAN! in Cygwin on Windows 10. Running via zsh 5.8.

$ sdk install java 8.0.275.hs-adpt # also tried 8.0.272-zulu and 20.3.0.r8-grl
$ sdk install kotlin 1.4.10 # I've tried several other versions though
$ sdk install kscript # I've tried several other versions though - even v2.0.1 fails the same way
$ kscript 'println("hello")'
[ERROR] compilation of 'println("hello")' failed
/c/cygwin64/home/Sean/.sdkman/candidates/kotlin/1.4.10/bin/kotlinc: line 80: java: command not found

I've been trying to debug the various shell scripts (where "debug" means set -x and echo commands), and it looks like it is the second invocation which can't find java. The invocation of kscript.app.KscriptKt is okay, but when kscript tries to execute the kotlin command line returned by KscriptKt, Kotlin can't find java.

Note that java is on the PATH, plus I've tried setting/exporting JAVACMD explicitly - it just seems like it isn't part of the environment at that point.

Also note that kotlinc can find Java under other circumstances; it is only when run from kscript that I see this problem.

eg

$ kotlinc -e 'println("Hello")'
Hello

seanf avatar Nov 22 '20 06:11 seanf

Sorry, I hit Enter by accident. Still filling in details. EDIT: finished.

seanf avatar Nov 22 '20 06:11 seanf

That's indeed strange. What's your kscript --version?

holgerbrandl avatar Dec 11 '20 20:12 holgerbrandl

Hey folks. I see this is quite an old issue, but I'm seeing the same problem when using git-bash on windows. Git for windows 2.3.1.1 SDKMAN 5.11.2+698 openjdk version "11.0.10" 2021-01-19 kotlin 1.5.0 kscript 3.1.0

Same symptoms as reported by @seanf

[kscript] [ERROR] compilation of './myscript.kts' failed /mnt/c/Users/blawlor/.sdkman/candidates/kotlin/current/bin/kotlinc: line 94: java: command not found

Any advice gratefully received.

blawlor avatar May 07 '21 16:05 blawlor

What's your kscript --version? This should tell what environment settings are picked up by kscript.

holgerbrandl avatar May 13 '21 11:05 holgerbrandl

Hi @holgerbrandl - thanks for getting back. Below is the output of running the kscript --version (including the odd stack trace at the end):

$ kscript --version kscript - Enhanced scripting support for Kotlin on *nix-based systems.

Usage: kscript [options]

The

Use '--clear-cache' to wipe cached script jars and urls

Options: -i --interactive Create interactive shell with dependencies as declared in script -t --text Enable stdin support API for more streamlined text processing --idea Open script in temporary Intellij session -s --silent Suppress status logging to stderr --package Package script and dependencies into self-dependent binary --add-bootstrap-header Prepend bash header that installs kscript if necessary

Copyright : 2020 Holger Brandl License : MIT Version : v3.1.0 Website : https://github.com/holgerbrandl/kscript Kotlin : Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.base/java.util.Collections$SingletonList.get(Collections.java:4849) at kscript.app.KscriptKt.main(Kscript.kt:84) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:64) at org.jetbrains.kotlin.runner.Main.run(Main.kt:176) at org.jetbrains.kotlin.runner.Main.main(Main.kt:186)

blawlor avatar May 13 '21 16:05 blawlor

It fails internally to split the system info retrieved by simply calling kotlin -version. What's its status if you call this directly? For me it reports

Kotlin version 1.5.0-release-749 (JRE 11.0.11+9-Ubuntu-0ubuntu2.20.04)

Initially, I suspected kotlin 1.5 to be the root cause, but this does not seem to be the case.

holgerbrandl avatar May 16 '21 20:05 holgerbrandl

I am seeing the same type of problem in GitHub Actions (msys, not cygwin) it seems, at least when running --version https://github.com/jayvdb/py2many/commit/ac6aca501cb35065273e7dc651dff559a9dfd13f

kotlin -version:

Kotlin version 1.4.30-release-302 (JRE 1.8.0_292-b10)

https://github.com/jayvdb/py2many/runs/2675360389?check_suite_focus=true

jayvdb avatar May 26 '21 13:05 jayvdb

If I install kotlin 1.5.0, kotlin -version:

Kotlin version 1.5.0-release-749 (JRE 1.8.0_292-b10)

jayvdb avatar May 26 '21 13:05 jayvdb

Hmm, this looks totally legit wrt to the used extraction codebit

val systemInfo = "Kotlin version 1.5.0-release-749 (JRE 1.8.0_292-b10)"

systemInfo.split('(')[0].removePrefix("Kotlin version").trim()

holgerbrandl avatar May 28 '21 11:05 holgerbrandl

Was having this problem and turned out to be caused by #347

amynbe avatar May 05 '22 14:05 amynbe

Closing it as it works now - there is a test suite for Cygwin.

aartiPl avatar Aug 27 '22 18:08 aartiPl