Piotr KrzemiĆski
06/13/2026, 10:12 AMexception: java.lang.ClassNotFoundException: kotlin.script.experimental.dependencies.Repository
when compiling their main.kts files? I think it started since Kotlin 2.4.0ilya.chernikov
06/17/2026, 2:10 PMPiotr KrzemiĆski
06/17/2026, 2:13 PMPiotr KrzemiĆski
06/17/2026, 2:20 PMilya.chernikov
06/17/2026, 2:33 PM-cp or use -script. The latter "magically" adds definition jar into classpath.
Have you seen it working before?Piotr KrzemiĆski
06/17/2026, 3:09 PMPiotr KrzemiĆski
06/18/2026, 6:14 AM-script indeed fixed the issue, but still reporting it as some kind of a regressionEugen Martynov
06/18/2026, 6:35 AMilya.chernikov
06/18/2026, 8:27 AMâŁCompiling ./.github/workflows/update-typings.main.kts before, and what it is now.
Adding -script is maybe not what you want, it is a command to execute the script, not to compile it.
So if under this line, I assume, you're compiling the script, you need to use -cp variant.Vampire
06/18/2026, 1:47 PM*.main.kts files are compiling properly, but not execute them.
So yes, specifying the classpath until Kotlin fixes it, is probably the better work-around.
With 2.3.10 and a script that does just println("FOO"), running like shown in the issue just compiles the script, using -script executes it.
Just that with 2.3.10 it just worked as the jar was automatically added to the classpath.ilya.chernikov
06/18/2026, 2:22 PMSo yes, specifying the classpath until Kotlin fixes it, is probably the better work-around.I do not think that we should fix it, tbh. I rather think that the old functionality is incorrect.
Vampire
06/18/2026, 2:24 PMkotlinc to compile the script, but have to look up where the jar is lying around to specify it on the classpath, or is there some magic [kotlin installation]/lib/kotlin-main-kts.jar you could specify?ilya.chernikov
06/18/2026, 2:31 PMmain-kts is a script supported by default but intended for running with the -script option. So the magic was added: if you're using -script with main.kts, you don't need anything else, no -X-es, no classpath, it all happens automatically.
In all other scenarios (including compiling of the script that is not designed to be compiled along with other sources), you need to instruct the compiler with all details.Vampire
06/18/2026, 2:54 PM*.main.kts script without executing it and without using -X-es?ilya.chernikov
06/19/2026, 7:49 AM-Xallow-any-scripts-in-source-roots and -cp, but the compilation of scripts is a non-standard operation.
A script definition is either designed for running, using the -script option, as in the main-kts case. Or a definition could be designed for compiling along with sources using the configuration property isStandalone(false). In the latter case, as in the case when you're using -Xallow-any-scripts-in-source-roots, you need to be aware of the implementation details of the script compilation, namely what object will be generated from the script, and how you should consume it. It is quite an advanced case, and the result is not a public API/ABI, is not stable, and can be changing from release to release.
So my assumption is that most likely you don't need to compile the main-kts script per se; you probably want to run it eventually.Vampire
06/19/2026, 8:04 AMVampire
06/19/2026, 8:04 AMilya.chernikov
06/19/2026, 8:22 AM-script-verify or something.
But I still believe that the original issue should not be fixed.Piotr KrzemiĆski
06/19/2026, 8:39 AMPiotr KrzemiĆski
06/19/2026, 8:43 AM#!/usr/bin/env kotlin
println("Hello world! The script is executed. To show it, let's throw")
error("ERROR")
and called:
% kotlinc -Xallow-any-scripts-in-source-roots -Xuse-fir-lt=false .github/workflows/test.main.kts
% kotlinc -script -Xallow-any-scripts-in-source-roots -Xuse-fir-lt=false .github/workflows/test.main.kts
Hello world! The script is executed. To show it, let's throw
java.lang.IllegalStateException: ERROR
at Test_main.<init>(test.main.kts:4)
so we see that only after adding -script, the script was executedVampire
06/19/2026, 9:05 AMilya.chernikov
06/19/2026, 9:58 AMbut we want to continuously check if it compiles fineThis could be a valid justification for some "dry"/"verify" feature, so please file an issue with the feature request. Meanwhile, please use
-Xallow-any-scripts-in-source-roots + -cp for the case.ilya.chernikov
06/19/2026, 10:02 AMBasicJvmScriptJarGenerator as an evaluator, and the latter generates a runnable jar from the script, so the execution part will become much cheaper.Vampire
06/19/2026, 10:04 AMPiotr KrzemiĆski
06/19/2026, 10:27 AMkotlinc -cp $(dirname $(dirname $(which kotlin)))/lib/kotlin-main-kts.jar -Xallow-any-scripts-in-source-roots -Xuse-fir-lt=false .github/workflows/test.main.kts
results in:
exception: java.lang.ClassNotFoundException: kotlin.script.experimental.dependencies.Repository
works this way both in 2.3.21 and 2.4.0. $(dirname $(dirname $(which kotlin)))/lib/kotlin-main-kts.jar alone resolves to the existing JAR correctly. Maybe the JAR is wrong? Tried other JARs from Kotlin's lib/ dir, doesn't workVampire
06/19/2026, 10:32 AM-verbose and you see the classpath it usesVampire
06/19/2026, 10:36 AMPiotr KrzemiĆski
06/19/2026, 10:53 AM-script and `-verbose`:
logging: configure scripting: Added template org.jetbrains.kotlin.mainKts.MainKtsScript from [/Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-main-kts.jar, /Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-reflect.jar, /Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-script-runtime.jar, /Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-stdlib.jar]
so calling the compiler to compile:
kotlinc -cp "$(dirname $(dirname $(which kotlin)))/lib/kotlin-main-kts.jar:$(dirname $(dirname $(which kotlin)))/lib/kotlin-reflect.jar:$(dirname $(dirname $(which kotlin)))/lib/kotlin-script-runtime.jar:$(dirname $(dirname $(which kotlin)))/lib/kotlin-stdlib.jar" -Xallow-any-scripts-in-source-roots -Xuse-fir-lt=false .github/workflows/test.main.kts
still fails with
exception: java.lang.ClassNotFoundException: kotlin.script.experimental.dependencies.RepositoryPiotr KrzemiĆski
06/19/2026, 10:54 AMkotlinc (the compiler) is better at running the scripts than in compiling them đ€ I'd expect the invocation of kotlinc to be as simple as possible to just compile because that's why I call this specific binary: kotlin*c*Vampire
06/19/2026, 10:55 AMecho?Piotr KrzemiĆski
06/19/2026, 10:56 AMecho "$(dirname $(dirname $(which kotlin)))/lib/kotlin-main-kts.jar:$(dirname $(dirname $(which kotlin)))/lib/kotlin-reflect.jar:$(dirname $(dirname $(which kotlin)))/lib/kotlin-script-runtime.jar:$(dirname $(dirname $(which kotlin)))/lib/kotlin-stdlib.jar"
/Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-main-kts.jar:/Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-reflect.jar:/Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-script-runtime.jar:/Users/piotr/.sdkman/candidates/kotlin/2.4.0/lib/kotlin-stdlib.jar
did you mean this?ilya.chernikov
06/19/2026, 11:24 AMkotlin-stdlib and kotlin-reflect to the classpath?Piotr KrzemiĆski
06/19/2026, 11:27 AMilya.chernikov
06/19/2026, 11:36 AMjar tf "$(dirname $(dirname $(which kotlin)))/lib/kotlin-main-kts.jar" | grep dependencies/Repository.class
?Piotr KrzemiĆski
06/19/2026, 11:37 AMkotlin/script/experimental/dependencies/Repository.class
looks saneilya.chernikov
06/19/2026, 11:41 AM-Xuse-fir-lt=falseilya.chernikov
06/19/2026, 11:41 AMPiotr KrzemiĆski
06/19/2026, 11:44 AM@file:DependsOn(...), which is a step forward, but how do I attach them to the classpath - where are they downloaded? is it a deterministic location?ilya.chernikov
06/19/2026, 11:49 AMPiotr KrzemiĆski
06/19/2026, 11:49 AMkotlinc -version
info: kotlinc-jvm 2.4.0 (JRE 23.0.1+11-39)Vampire
06/19/2026, 11:58 AMVampire
06/19/2026, 12:03 PM-verify-script FR đ