Thread
#compose
    Timo Drick

    Timo Drick

    1 year ago
    Is it possible to compile compose code as KotlinScript? Maybe someone can give me a hint. I think i have to enable the compiler plugin of compose. But i do not know how to do that.
    m

    Mark Murphy

    1 year ago
    My guess is that this devolves to: how to we get Kotlin compiler plugins and the IR backend to operate in a scripting environment?
    Timo Drick

    Timo Drick

    1 year ago
    For me it would be enough when i can compile compose code during runtime inside of a kotlin program that itself is also compiled with the Compose plugin.
    Or more specific i want to compile it and execute it during runtime
    SrSouza

    SrSouza

    1 year ago
    I think you ask in #scripting
    Timo Drick

    Timo Drick

    1 year ago
    Ok when i enable the compose plugin for the compiler i get now this error: exception: java.lang.IllegalStateException: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar is not compatible with this version of compiler
    So it looks like compose still uses a modified kotlin compiler
    Adam Powell

    Adam Powell

    1 year ago
    nah, no kotlinc modifications, compose has used standard kotlinc for some time now. it is tightly coupled with particular versions of kotlinc, however, as the plugin apis often change in incompatible ways. if you're using a newer kotlinc that compose hasn't been updated/tested against yet there's a flag to disable the version check and try anyway if you're feeling lucky. you should be able to find it searching this channel
    j

    jw

    1 year ago
    The flag also triggers with Kotlin/Native even if you're on the right version. So perhaps scripting behaves the same where you need to always disable the check.
    Timo Drick

    Timo Drick

    1 year ago
    Do you mean this flag:Xskip-runtime-version-check unfortunatley i think i do something else wrong.
    So when i compile a very simple compose for desktop project with "./gradlew -d compileKotlin" i see the compiler arguments gradle uses in the line: contains :compileKotlin Kotlin compiler args: When i use this arguments to run kontlinc i get this error. Also tried to add -Xskip-runtime-version-check.
    logging: using Kotlin home directory /home/timo/devutils/kotlinc
    logging: using JVM IR backend
    logging: configuring the compilation environment
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
    WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    exception: java.lang.IllegalStateException: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar is not compatible with this version of compiler
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:592)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:132)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:172)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:426)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:226)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:152)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:76)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:45)
    	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:227)
    	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:222)
    	at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:214)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:271)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    	at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:87)
    	at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:44)
    Caused by: java.lang.AbstractMethodError: Receiver class androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar does not define or inherit an implementation of the resolved method 'abstract void registerProjectComponents(com.intellij.mock.MockProject, org.jetbrains.kotlin.config.CompilerConfiguration)' of interface org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar.
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:584)
    	... 23 more
    Adam Powell

    Adam Powell

    1 year ago
    the "caused by" looks like an incompatible change in the kotlinc <-> plugin interface layers between 1.4.31 and the kotlinc version you're using
    Timo Drick

    Timo Drick

    1 year ago
    but i am using 1.4.31 Just downloaded this version
    kotlinc -version
    OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
    info: kotlinc-jvm 1.4.31 (JRE 14.0.2+12-Ubuntu-120.04)
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
    WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    hmm ok maybe i could try to use openjdk 15
    Adam Powell

    Adam Powell

    1 year ago
    I don't think that's going to change the underlying incompatibility between the versions of kotlinc and the compose plugin in play here
    Timo Drick

    Timo Drick

    1 year ago
    I get the same error when i use K2JVMCompiler().exec(...) during runtime inside of a compose for desktop program and try to compile simple compose for desktop application.
    Colton Idle

    Colton Idle

    1 year ago
    Maybe upload a sample project with this? I can try getting it to work on my local as well.
    Timo Drick

    Timo Drick

    1 year ago
    Ok i created a project here: https://gitlab.com/compose1/runtime-compose-compiler It would be really great if it is possible to get this running. Because than things like this:https://kotlinlang.slack.com/archives/C01D6HTPATV/p1617387096360300 getting possible for Compose UI
    Hmm not sure why. But now it works for me 😄 Did not changed anything in the code. Now i have to find out how to run it as script. Or maybe reload the class during runtime.
    It is very wired but it works. I can also executed the generated class file and see that Compose window is shown.
    Ok i think it was not working because i used
    implementation(kotlin("compiler")) // instead of kotlin("compiler-embeddable")
    And when i change this it takes only the other version when i reload all gradle projects not when i just compiled.
    But good news i was able to solve all my problems. And now it is working. So i can compile compose code inside of a compose application and can reload this code and execute it 😄