Olaf Gottschalk
08/06/2024, 6:22 AMobject TralaScriptConfiguration : ScriptCompilationConfiguration(
{
defaultImports(tralaDefaultImports)
jvm {
jvmTarget("11")
compilerOptions("-Xcontext-receivers")
updateClasspath(...)
}
}
)
This seems to do the trick... am I right? I was not immediately on this track as I was looking for a freeCompilerArgs
function...Dylan
08/06/2024, 4:15 PMOlaf Gottschalk
08/09/2024, 11:22 AMScriptCompilationConfiguration
are working properly when calling the eval
on the scripting host, but are ignored when IntelliJ handles the same script file type in its editor... specifically, I added some checks and declare failures using markFailureResult
in refineConfiguration { beforeParsing { ... }}
- but even if I just return an error, the editor does not show it at all...Vampire
08/14/2024, 2:30 PMTom Mulcahy
09/12/2024, 10:24 PMimport Foo.Companion.bar
works, but Android Studio seems to expect import Foo_main.Foo.Companion.bar
. What IDE are you all using to write kts? Is there a way to use Android Studio (without a sea of red and no auto-complete)?zt
09/19/2024, 2:50 AMDaniel Souza Bertoldi
09/26/2024, 1:03 PMio
dependencies, no ideia why. I'll post my code + the error in the thread.Jintin
10/16/2024, 11:19 AMOlaf Gottschalk
11/04/2024, 10:56 AMScriptCompilationConfiguration
?
Does anybody know how to do it? Thanks!Eugen Martynov
11/04/2024, 11:53 AMWayZer
11/10/2024, 1:43 PMprotected
in base class with new scripting version(KT 2.0+ library)
Workaround `@Suppress("INVISIBLE_REFERENCE")`: works when compile and runtime.Jason
11/14/2024, 11:31 PMmbonnin
11/20/2024, 3:30 PMspierce7
11/21/2024, 4:01 PMyostane
12/05/2024, 4:20 PMIstván Mészáros
12/06/2024, 9:21 AMNino
12/16/2024, 12:32 PMkotlin
CLI is already dead ? Such a same it seemed such a beautiful and powerful replacement for bash files 😞
• Then I tried Kotlin Notebook but they never mentionned that it needed Intellij Ultimate. I lost half a day trying to download the plugin until I understood. Greedy fuckers 😞
• Then I tried ki shell
but I don't quite understand what is it for. Looks like Kotlin Playground locally, which doesn't fit my need.
• Then I'm trying to use kotlinc -script
but there's no documentation (https://kotlinlang.org/docs/command-line.html#run-scripts), or I don't understand the relation between the overly complex documentation linked there (https://kotlinlang.org/docs/custom-script-deps-tutorial.html) and a simple CLI-invoked script in Kotlin.
Please guide me in this maze I'm already on the verge to going back to bash scripting. What tool would you use to produce the specified script ?Piotr Krzemiński
01/24/2025, 6:00 PMe: java.lang.ExceptionInInitializerError
...
Caused by: java.lang.ClassCastException: class org.jetbrains.kotlin.idea.KotlinFileType cannot be cast to class org.jetbrains.kotlin.com.intellij.openapi.fileTypes.LanguageFileType (org.jetbrains.kotlin.idea.KotlinFileType and org.jetbrains.kotlin.com.intellij.openapi.fileTypes.LanguageFileType are in unnamed module of loader java.net.URLClassLoader @5d5c04f9
...
my code in the threadPiotr Krzemiński
01/27/2025, 3:28 PM-jvm
- just @file:DependsOn("it.krzeminski:snakeyaml-engine-kmp:3.1.0")
works now 🙂ribesg
02/19/2025, 2:11 PM.main.kts
file as a Kotlin Script and provide highlighting, completion and everything else? I just have a folder containing my scripts for now and it just treats them as plain textOlaf 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!
OlafPiotr Krzemiński
02/20/2025, 1:00 PM@file:DependsOn("...")
? 🙈 scripting would have to know where to look for the TOML file, and it's non-trivial to infer. It could traverse starting from the script's location, up the file tree, until it finds gradle/libs.versions.toml
Piotr Krzemiński
02/20/2025, 3:06 PM.github/workflows/end-to-end-tests.main.kts
here: https://github.com/typesafegithub/github-workflows-kt/actions/runs/13436465865/job/37545104505?pr=1830 causes:
java.lang.NoClassDefFoundError: kotlinx/io/unsafe/UnsafeBufferOperations
.
So far I checked that:
• @file:DependsOn("io.github.typesafegithub:action-updates-checker:3.2.1-SNAPSHOT")
and any pieces that depend on functions from it, it works - so this package is to blame
• UnsafeBufferOperations
was introduced in kotlinx-io 0.5.0
• ktor started using kotlinx-io starting 3.1.0 in this commit
Something must still depend on kotlinx-io older than 0.5.0, but I cannot pin it down...Rob Elliot
02/28/2025, 1:20 PMScriptCompilationConfiguration
to require a specific return type for the script? So that the script will fail to compile if the last expression is not of that type?WayZer
03/29/2025, 2:50 PMobject TableVersion : IdTable<String>("TableVersion") {
// can't use `text` as h2db don't support for primaryKey
override val id: Column<EntityID<String>> = varchar("table", 64).entityId()
override val primaryKey: PrimaryKey = PrimaryKey(id) // h2database#2191
//...
}
will complain PrimaryKey
class (inner class of Table) is not found.
This example works with -language-version=1.9
zt
04/04/2025, 4:12 AMMETA-INF/kotlin/script/templates/dev.zt64.composables.ComposableScript
but when I select the script nothing is resolved and the classpath is missing dependencies. I've tried adding isStandalone(false)
to my compilation configuration as well
here is the repository https://github.com/zt64/compose-scriptsOlaf Gottschalk
04/25/2025, 5:41 AM@TransformationDsl
infix fun <D : Any, VO> SetOperation<S, D>.by(valueMapper: ValueMapper<Any?, VO>) =
apply { source = source.map(valueMapper) }
When this function is used in "normal IntelliJ" contexts, a call like this compiles and works just fine:
set optional "overallWeightTransportation" from "GrossWeightTransportationQuantity" by unitCodeMapper
If you look very closely to my generics, the generic type VO
is not really relevant to this function, it has not bounds, the usage of the parameter valueMapper
when passed to the map
function does not care about this generic type, as map
accepts everything.
I did not realize this was over-engineered until when compiled with the script compiler I got this error:
set optional "overallWeightTransportation" from "GrossWeightTransportationQuantity" by unitCodeMapper //later mandatory
^^ Cannot infer type for this parameter. Specify it explicitly.
^^ Not enough information to infer type argument for 'VO'.
The key question is now: why does it work just fine in IntelliJ, but not in scripting compilation?
Solution for my immediate problem was to replace VO
with *
of course... but the question remains... ;-)louiscad
05/05/2025, 12:34 AMritesh
05/09/2025, 3:11 PMDaniel Pitts
05/10/2025, 4:41 PM