Would compose-jb work with scripting?
# scripting
z
Would compose-jb work with scripting?
m
If you're talking
*.main.kts
, I'm not sure there's an easy way to configure the compiler plugin. There are ways for sure but that doesn't sound particularly straightforward
b
It certainly won't work with .main.kts, because that itself is powered by a plugin. You could write your own script backend that embeds compose plugin for something like .compose.kts
s
Anyone had already achieve this? Compose relay in IR, does the scripting api already support it?
z
Ok so I think I'll have to use the
-Xplugin
arg, though I don't know how. I tried adding this into my compilation configuration but that just says
The following compiler arguments are ignored on script compilation: -Xplugin
when the script is ran
Copy code
compilerOptions.append("-Xplugin=/home/nick/.gradle/caches/jars-9/21911321bfa89962cc8dbb6574b040d5/compose-gradle-plugin-1.2.0.jar")
Copy code
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4")

import kotlinx.coroutines.runBlocking
import androidx.compose.runtime.*
import androidx.compose.material.*
import androidx.compose.ui.window.*

runBlocking {
    println("Hello")

    application {
        Window(
            onCloseRequest = ::exitApplication
        ) {
            Text("Hello, world!")
        }
    }
}
The println gets ran, but no window shows up and the script just closes with no errors
s
@ilya.chernikov Hi, sorry to ping you. The last time I check, scripting was not using the IR Compiler? I think Is this still the case and if not, compose compiler plugin could work with scripting or there is some limitation that is still present in Kotlin 1.8 Beta that you can share maybe with us?
i
@SrSouza, absolutely no problem, please ping me, if you think that I should be involved in the discussion. Scripting compilation pipeline uses IR backend by default since at least 1.7.0 (I think even since some earlier release). But there is a problem with adding compiler plugins to the pipeline (https://youtrack.jetbrains.com/issue/KT-54095). I may be able to address it in 1.8.20, but I cannot promise now. So probably the only accessible option for now is to use CLI pipeline (e.g. like in this test - https://github.com/JetBrains/kotlin/blob/1.8.0/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsIT.kt#L145)
🙏 1
z
@ilya.chernikov I've been trying for a while now to get this working but it won't. Ive been passing the Xplugin arg but it doesn't actually apply the plugin which transforms the packages. Any idea?
i
@zt, are you using cli compiler and pass -Xplugin as a cli arg? If so, does it work if you manually convert your script to a similar regular kt file?
z
Yes, I'm passing the -Xplugin arg to the cli compiler. I tried with a regular kt file like you said but that didn't work either. Just says
Exception in thread "main" java.lang.NoClassDefFoundError: androidx/compose/ui/window/Application_desktopKt