jbang: Can't run Kotlin files in Windows with more than one dependency in the classpath
Describe the bug Can’t run Kotlin files in Windows with more than one dependency in the classpath
To Reproduce Steps to reproduce the behavior:
- Create a
KotlinBug.ktfile with the following content:
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.squareup.okhttp3:okhttp:4.10.0
//DEPS org.json:json:20220320
import okhttp3.OkHttpClient
import org.json.JSONObject
fun main() {
val jokeRequest = okhttp3.Request.Builder()
.url("https://api.chucknorris.io/jokes/random?category=dev")
.build()
val jokeResponse = OkHttpClient().newCall(jokeRequest).execute()
val joke = JSONObject(jokeResponse.body!!.string())
println(joke["value"])
}
- Run it in a
Windows 10host withPowershell, like this:
jbang .\KotlinBug.kt
- See the following error:
[jbang] Building jar...
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okio\okio-jvm\3.0.0\okio-jvm-3.0.0.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk8\1.5.31\kotlin-stdlib-jdk8-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk7\1.5.31\kotlin-stdlib-jdk7-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.5.31\kotlin-stdlib-common-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.20\kotlin-stdlib-1.6.20.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\json\json\20220320\json-20220320.jar
[jbang] [ERROR] Error during compile
[jbang] Run with --verbose for more details
Expected behavior
- The script should just run fine as it does in an
Unixhost:
❯ jbang KotlinBug.kt
[jbang] Building jar...
When Chuck Norris break the build, you can't fix it, because there is not a single line of code left.
JBang version
[jbang] jbang version 0.98.0
Cache: C:\Users\gustavo.rodriguezl\.jbang\cache
Config: C:\Users\gustavo.rodriguezl\.jbang
Repository:C:\Users\gustavo.rodriguezl\.m2\repository
0.98.0
Additional context
👀👇👇
This is how the execution looks if verbose mode is enabled
gustavo.rodriguezl ~\src\garodriguezlp\jbang-kotlin-bug
❯ jbang --verbose run .\KotlinBug.kt
[jbang] jbang version 0.98.0
[jbang] Build required as C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar not readable or not found.
[jbang] Downloading Kotlin 1.6.10. Be patient, this can take several minutes...
[jbang] Downloading https://github.com/JetBrains/kotlin/releases/download/v1.6.10/kotlin-compiler-1.6.10.zip
[jbang] Redirected to: https://objects.githubusercontent.com/github-production-release-asset-2e65be/3432266/321575a3-fab9-4e5a-9a47-dda6e8303e47?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220902%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220902T191331Z&X-Amz-Expires=300&X-Amz-Signature=429d8a730640798c6f4318335b48b4313757750623969938dc0e41eec48ac37c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=3432266&response-content-disposition=attachment%3B%20filename%3Dkotlin-compiler-1.6.10.zip&response-content-type=application%2Foctet-stream
[jbang] Downloaded file https://objects.githubusercontent.com/github-production-release-asset-2e65be/3432266/321575a3-fab9-4e5a-9a47-dda6e8303e47?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220902%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220902T191331Z&X-Amz-Expires=300&X-Amz-Signature=429d8a730640798c6f4318335b48b4313757750623969938dc0e41eec48ac37c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=3432266&response-content-disposition=attachment%3B%20filename%3Dkotlin-compiler-1.6.10.zip&response-content-type=application%2Foctet-stream
[jbang] Installing Kotlin 1.6.10...
[jbang] Unpacking to C:\Users\gustavo.rodriguezl\.jbang\cache\kotlincs\1.6.10
[jbang] Repositories: mavencentral=https://repo1.maven.org/maven2/
[jbang] Resolving dependencies...
[jbang] com.squareup.okhttp3:okhttp:jar:4.10.0
org.json:json:jar:20220320
Done
[jbang] Dependencies resolved
[jbang] Building jar...
[jbang] Compile: C:\Users\gustavo.rodriguezl\.jbang\cache\kotlincs\1.6.10\kotlinc\bin\kotlinc.bat -classpath C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okhttp3\okhttp\4.10.0\okhttp-4.10.0.jar;C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okio\okio-jvm\3.0.0\okio-jvm-3.0.0.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk8\1.5.31\kotlin-stdlib-jdk8-1.5.31.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk7\1.5.31\kotlin-stdlib-jdk7-1.5.31.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.5.31\kotlin-stdlib-common-1.5.31.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.20\kotlin-stdlib-1.6.20.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\json\json\20220320\json-20220320.jar -d C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar.tmp C:\Users\gustavo.rodriguezl\src\garodriguezlp\jbang-kotlin-bug\KotlinBug.kt
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okio\okio-jvm\3.0.0\okio-jvm-3.0.0.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk8\1.5.31\kotlin-stdlib-jdk8-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk7\1.5.31\kotlin-stdlib-jdk7-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.5.31\kotlin-stdlib-common-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.20\kotlin-stdlib-1.6.20.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\json\json\20220320\json-20220320.jar
[jbang] Deleting folder C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar.tmp
[jbang] [ERROR] Error during compile
dev.jbang.cli.ExitException: Error during compile
at dev.jbang.source.builders.BaseBuilder.runCompiler(BaseBuilder.java:191)
at dev.jbang.source.builders.BaseBuilder.runCompiler(BaseBuilder.java:179)
at dev.jbang.source.builders.BaseBuilder.compile(BaseBuilder.java:152)
at dev.jbang.source.builders.BaseBuilder.build(BaseBuilder.java:105)
at dev.jbang.source.builders.BaseBuilder.build(BaseBuilder.java:30)
at dev.jbang.cli.Run.prepareArtifacts(Run.java:133)
at dev.jbang.cli.Run.doCall(Run.java:104)
at dev.jbang.cli.BaseCommand.call(BaseCommand.java:136)
at dev.jbang.cli.BaseCommand.call(BaseCommand.java:20)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
at dev.jbang.cli.JBang$3.handle(JBang.java:151)
at dev.jbang.cli.JBang$3.handle(JBang.java:146)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
at picocli.CommandLine.execute(CommandLine.java:2078)
at dev.jbang.Main.main(Main.java:14)
[jbang] If you believe this a bug in jbang, open an issue at https://github.com/jbangdev/jbang/issues
And this is what I see if I dig into and tweek the `kotlinc.bat` file
- Actually, I’m talking about modifying the
kotlinc.batfile line 69 by puttig before andechocommand to see what is the value of theKOTLIN_OPTSvariable.- Like this:
echo "KOTLIN_OPTS=%KOTLIN_OPTS%"
❯ jbang --verbose run .\KotlinBug.kt
[jbang] jbang version 0.98.0
[jbang] Build required as C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar not readable or not found.
[jbang] Repositories: mavencentral=https://repo1.maven.org/maven2/
[jbang] Building jar...
[jbang] Compile: C:\Users\gustavo.rodriguezl\.jbang\cache\kotlincs\1.6.10\kotlinc\bin\kotlinc.bat -classpath C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okhttp3\okhttp\4.10.0\okhttp-4.10.0.jar;C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okio\okio-jvm\3.0.0\okio-jvm-3.0.0.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk8\1.5.31\kotlin-stdlib-jdk8-1.5.31.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk7\1.5.31\kotlin-stdlib-jdk7-1.5.31.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.5.31\kotlin-stdlib-common-1.5.31.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.20\kotlin-stdlib-1.6.20.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\gustavo.rodriguezl\.m2\repository\org\json\json\20220320\json-20220320.jar -d C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar.tmp C:\Users\gustavo.rodriguezl\src\garodriguezlp\jbang-kotlin-bug\KotlinBug.kt
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okio\okio-jvm\3.0.0\okio-jvm-3.0.0.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk8\1.5.31\kotlin-stdlib-jdk8-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk7\1.5.31\kotlin-stdlib-jdk7-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.5.31\kotlin-stdlib-common-1.5.31.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.20\kotlin-stdlib-1.6.20.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar
error: source entry is not a Kotlin file: C:\Users\gustavo.rodriguezl\.m2\repository\org\json\json\20220320\json-20220320.jar
[jbang] Deleting folder C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar.tmp
[jbang] [ERROR] Error during compile
dev.jbang.cli.ExitException: Error during compile
at dev.jbang.source.builders.BaseBuilder.runCompiler(BaseBuilder.java:191)
at dev.jbang.source.builders.BaseBuilder.runCompiler(BaseBuilder.java:179)
at dev.jbang.source.builders.BaseBuilder.compile(BaseBuilder.java:152)
at dev.jbang.source.builders.BaseBuilder.build(BaseBuilder.java:105)
at dev.jbang.source.builders.BaseBuilder.build(BaseBuilder.java:30)
at dev.jbang.cli.Run.prepareArtifacts(Run.java:133)
at dev.jbang.cli.Run.doCall(Run.java:104)
at dev.jbang.cli.BaseCommand.call(BaseCommand.java:136)
at dev.jbang.cli.BaseCommand.call(BaseCommand.java:20)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
at dev.jbang.cli.JBang$3.handle(JBang.java:151)
at dev.jbang.cli.JBang$3.handle(JBang.java:146)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
at picocli.CommandLine.execute(CommandLine.java:2078)
at dev.jbang.Main.main(Main.java:14)
[jbang] If you believe this a bug in jbang, open an issue at https://github.com/jbangdev/jbang/issues
"KOTLIN_OPTS= "-classpath" "C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okhttp3\okhttp\4.10.0\okhttp-4.10.0.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\com\squareup\okio\okio-jvm\3.0.0\okio-jvm-3.0.0.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk8\1.5.31\kotlin-stdlib-jdk8-1.5.31.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-jdk7\1.5.31\kotlin-stdlib-jdk7-1.5.31.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.5.31\kotlin-stdlib-common-1.5.31.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.20\kotlin-stdlib-1.6.20.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar" "C:\Users\gustavo.rodriguezl\.m2\repository\org\json\json\20220320\json-20220320.jar" "-d" "C:\Users\gustavo.rodriguezl\.jbang\cache\jars\KotlinBug.kt.b1dcd226c361b16405f16afa01abf35b4bc837922d85cd9439255613c8efff4d.jar.tmp" "C:\Users\gustavo.rodriguezl\src\garodriguezlp\jbang-kotlin-bug\KotlinBug.kt""
- As you can see (in this👆last debug line), the classpath is not being passed correctly to the Kotlin compiler. The classpath is being passed as multiple arguments instead of a single argument separated by
;semicolon.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 23 (15 by maintainers)
Commits related to this issue
- fix: Fixed passing arguments to .bat files on Windows Fixes #1447 — committed to quintesse/jbang by quintesse 2 years ago
- fix: Fixed passing arguments to .bat files on Windows Fixes #1447 — committed to quintesse/jbang by quintesse 2 years ago
- fix: Fixed passing arguments to .bat files on Windows Fixes #1447 — committed to quintesse/jbang by quintesse 2 years ago
With PR #1449 the KotlinBug.kt now compiles correctly and it doesn’t seem to be causing any others problems.
Great examination. No wonder windows users are hard to support with this level of inconsistency.
Do you wanna make a pr for commandBuffer ?
I think the concept of a
CommandBuffermight be nice solution, even if it’s simply to take a list of arguments and turn them intoEg. something like: