Olaf Gottschalk
02/20/2025, 9:29 AM@KotlinScript
annotation like this:
const val TRALA_FILE_EXTENSION = "trala.kts"
@KotlinScript(
displayName = "TraLa Script",
fileExtension = TRALA_FILE_EXTENSION,
compilationConfiguration = TraLaScriptConfiguration::class
)
abstract class TraLaScript
plus, there is a resource file at this location:
resources/META-INF/kotlin/script/templates/com.bmw.transformation.scripting.TraLaScript
(which is empty)
The compilation configuration looks like this:
@Suppress("JavaIoSerializableObjectMustHaveReadResolve")
object TraLaScriptConfiguration : ScriptCompilationConfiguration(
{
defaultImports(traLaDefaultImports)
ide {
acceptedLocations(ScriptAcceptedLocation.Everywhere)
}
jvm {
jvmTarget("17")
compilerOptions("-Xcontext-receivers")
}
}
)
The idea is that any project that uses my DSL library can have files anywhere (see acceptedLocations
with the extension .trala.kts
and the editor will offer syntax highlight and code completion / inspection.
This used to work. Sometimes I had to restart IntelliJ... it was never straight forward. But it worked.
Now, I cannot see any way to make the editor behave like I want. And I do not know what changed.
In projects that DEPEND on my lib (with this setup), nothing works any more.
In my library project itself, the default imports don't seem to work anymore! When I add a new file foo.trala.kts
and start typing code, it inserts import statements that it should not, because they are part of the default imports...
What am I doing wrong here? Is there any good documentation on these matters?
Thanks!
Olafilya.chernikov
03/21/2025, 1:46 PMisStandalone(false)
to your ScriptCompilationConfiguration
. Although this is an old change - scripts with definitions without it are ignored in source roots by default. So it is quite suspicious that you're seeing it only now, but maybe something else was at play. For example there is a workaround with -Xallow-any-scripts-in-source-roots
compiler flag.ilya.chernikov
03/21/2025, 1:47 PMOlaf Gottschalk
04/25/2025, 5:12 AMisStandalone(false)
but still, nothing changes. The scripts are not getting their default imports at all, they are basically completely broken in IntelliJ. I would like to open a YT issue, but can it really be I am the only one who uses this? Is there any kind of documentation I can read again, like a demo project that showcases this rather odd setup with the "magic" ScriptCompilationConfiguration
class and the magic resource file META-INF/kotlin/script/templates/...
? I would like to test that in order to even write a proper YT issue as I cannot post all of my script language code. Thanks!ilya.chernikov
04/28/2025, 9:46 AMisStandalone(false)
) is considered quite an advanced case, where you need to understand quite well how your scripts will interact with the other sources in the project.
Therefore, we hide it under the opt-ins, and thus, we hope, there are not many users who use this.
Anyway, I recommend you to file an issue as is, using just the description you gave above, and we'll test the functionality on our tests and come back to you on it later.
cc: @Vladislav KoshkinOlaf Gottschalk
05/05/2025, 11:46 AMVladislav Koshkin
05/05/2025, 11:48 AMOlaf Gottschalk
05/20/2025, 1:23 PM@KotlinScript
annotated file is recognized only when not in K2 mode. I also added a readme with two images showing exactly how it looks on my screen with the two different modes!
Thanks!Vladislav Koshkin
06/05/2025, 4:38 PM[KOTLIN_SCRIPTING] Cannot load script definition class demodsl.MyDslScript
java.lang.UnsupportedClassVersionError: demodsl/MyDslScript has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at com.intellij.util.lang.UrlClassLoader.consumeClassData(UrlClassLoader.java:303)
at com.intellij.util.lang.FileLoader.findClass(FileLoader.java:187)
at com.intellij.util.lang.ClassPath.findClassInLoader(ClassPath.java:240)
at com.intellij.util.lang.ClassPath.findClass(ClassPath.java:190)
4. so I just removed
kotlin {
jvmToolchain(21)
}
and rebuild the project
there is also an action in Kotlin Scripting Settings that allow you to force re-scan your classpath, it was handy in that caseVladislav Koshkin
06/05/2025, 4:39 PMOlaf Gottschalk
06/06/2025, 6:56 AMOlaf Gottschalk
06/06/2025, 7:11 AMprintln
works, but nothing from my project is available, even when trying to import manually, even though the code completion offers my packages...
Any idea why that is?
I wanted to attach screenshots, but.... Slack does not accept them, they all get a red exclamation mark...Olaf Gottschalk
06/06/2025, 7:17 AMOlaf Gottschalk
06/06/2025, 7:26 AMOlaf Gottschalk
06/06/2025, 7:28 AMOlaf Gottschalk
06/06/2025, 7:29 AMOlaf Gottschalk
06/06/2025, 7:34 AMOlaf Gottschalk
06/06/2025, 7:42 AMOlaf Gottschalk
06/06/2025, 7:43 AMOlaf Gottschalk
06/06/2025, 7:45 AMOlaf Gottschalk
06/06/2025, 8:48 AMOlaf Gottschalk
06/06/2025, 8:49 AMOlaf Gottschalk
06/06/2025, 8:50 AMOlaf Gottschalk
06/17/2025, 7:37 AMVladislav Koshkin
06/26/2025, 9:43 AMOlaf Gottschalk
07/14/2025, 11:56 AMOlaf Gottschalk
07/14/2025, 11:57 AMVladislav Koshkin
07/14/2025, 12:08 PMacceptedLocations
key properly (ScriptAcceptedLocation.Everywhere should include test folder)
2. we do not detect definition when we put compiled jar as gradle dependencyVladislav Koshkin
07/14/2025, 12:09 PMVladislav Koshkin
07/14/2025, 12:11 PMOlaf Gottschalk
07/14/2025, 2:10 PMOlaf Gottschalk
07/14/2025, 2:13 PMOlaf Gottschalk
07/14/2025, 2:14 PMVladislav Koshkin
07/14/2025, 6:15 PMVladislav Koshkin
07/17/2025, 9:40 AMVladislav Koshkin
07/17/2025, 9:40 AMOlaf Gottschalk
07/17/2025, 9:41 AMVladislav Koshkin
07/17/2025, 10:23 AM@KotlinScript(
displayName = "MyDsl Script",
fileExtension = "mydsl.kts",
filePathPattern = ".*\\.mydsl\\.kts", //<<<<<<<<<<<<<<-----
compilationConfiguration = MyDslScriptConfiguration::class
)
next, I have to be sure that my jar build with gradle publish task contains all the script dsl:
so I've added this to my build.gradle.kts file:
publishing {
publications {
create<MavenPublication>("something") {
groupId = "com.testing.demo-dsl"
artifactId = "demo-dsl"
version = rootProject.version.toString()
from(components["kotlin"])
}
}
repositories {
mavenLocal()
}
}
then I took a look inside the jar, everything was in place:
❯ ls -l
total 24
-rw-r--r-- 1 Vladislav.Koshkin staff 12145 17 Jul 12:00 demo-dsl-1.0-SNAPSHOT.jar
~/.gradle/caches/modules-2/files-2.1/com.testing.demo-dsl/demo-dsl/1.0-SNAPSHOT/290f2b6777ee91619b9d52f05a52e03d97d64ad4
❯ jar tvf demo-dsl-1.0-SNAPSHOT.jar
0 Thu Jul 17 11:58:00 CEST 2025 META-INF/
25 Thu Jun 05 18:32:52 CEST 2025 META-INF/MANIFEST.MF
0 Thu Jul 17 11:58:00 CEST 2025 demodsl/
678 Thu Jul 17 11:58:00 CEST 2025 demodsl/MyDslScript.class
1338 Thu Jul 17 11:58:00 CEST 2025 demodsl/DemoDslKt.class
4522 Thu Jul 17 11:58:00 CEST 2025 demodsl/MyDslImpl.class
4447 Thu Jul 17 11:58:00 CEST 2025 demodsl/MyDslScriptConfiguration.class
667 Thu Jul 17 11:58:00 CEST 2025 demodsl/Shout.class
663 Thu Jul 17 11:58:00 CEST 2025 demodsl/Say.class
2734 Thu Jul 17 11:58:00 CEST 2025 demodsl/ScriptingKt.class
535 Thu Jul 17 11:58:00 CEST 2025 demodsl/MyDslMarker.class
837 Thu Jul 17 11:58:00 CEST 2025 demodsl/MyDsl.class
434 Thu Jul 17 11:58:00 CEST 2025 demodsl/Verb.class
828 Thu Jul 17 11:58:00 CEST 2025 demodsl/MyDsl$DefaultImpls.class
71 Thu Jul 17 11:58:00 CEST 2025 META-INF/demo-dsl.kotlin_module
1690 Thu Jul 17 11:58:00 CEST 2025 MainKt.class
0 Thu Jul 17 11:57:58 CEST 2025 META-INF/kotlin/
0 Thu Jul 17 11:57:58 CEST 2025 META-INF/kotlin/script/
0 Thu Jul 17 11:57:58 CEST 2025 META-INF/kotlin/script/templates/
0 Thu Jul 17 11:57:58 CEST 2025 META-INF/kotlin/script/templates/demodsl.MyDslScript
then I've create a new gradle project and put this line in my build.gradle.kts
implementation("com.testing.demo-dsl:demo-dsl:1.0-SNAPSHOT")
and then I did scan classpath action via kotlin scripting settings tab
and when I created a .mydsl.kts file - highlighting started to workVladislav Koshkin
07/17/2025, 10:24 AMVladislav Koshkin
07/17/2025, 10:25 AMVladislav Koshkin
07/17/2025, 10:25 AMVladislav Koshkin
07/17/2025, 10:26 AMVladislav Koshkin
07/17/2025, 10:28 AMVladislav Koshkin
07/17/2025, 12:33 PMfirst thing - file extension was not enough - I had to add filePathPattern like this:never mind - this one is wrong your definition was all right
Olaf Gottschalk
07/17/2025, 1:04 PMOlaf Gottschalk
07/18/2025, 9:48 AMOlaf Gottschalk
07/18/2025, 9:51 AMtrala.kts
files I open end up all in red. What do I need to do to see just why it does not understand this script?Vladislav Koshkin
07/18/2025, 9:51 AMOlaf Gottschalk
07/18/2025, 9:51 AMOlaf Gottschalk
07/18/2025, 9:52 AMOlaf Gottschalk
07/18/2025, 9:52 AMVladislav Koshkin
07/18/2025, 9:53 AMOlaf Gottschalk
07/18/2025, 9:53 AMOlaf Gottschalk
07/18/2025, 9:55 AMOlaf Gottschalk
07/18/2025, 9:55 AMOlaf Gottschalk
07/18/2025, 11:22 AMOlaf Gottschalk
07/22/2025, 8:37 AMTraLa Script
according to the Status bar indicator, do NOT work again. I am so frustrated with this. What should I look for in this situation to see WHY it does not work?Olaf Gottschalk
07/22/2025, 8:39 AMjsonTransformaion
which takes a code block. Typing the letters j-s-o-n
and waiting for code completion offers shows stuff, but NOT my method. Where does that "stuff" come from, why is MY function missing even though the script type is correctly identified and shown?Olaf Gottschalk
07/22/2025, 8:40 AM