Slackbot
09/27/2022, 8:01 AMmelix
09/27/2022, 8:02 AMpublic static void whenKotlinSupportPresent(Project p, Consumer<? super Project> action) {
p.getPluginManager().withPlugin("org.jetbrains.kotlin.jvm", unused -> action.accept(p));
}
melix
09/27/2022, 8:02 AMmelix
09/27/2022, 8:03 AMmelix
09/27/2022, 8:03 AMtasks.withType(KotlinCompile.class).configureEach(kotlinCompile -> { ... }
melix
09/27/2022, 8:04 AMjava.lang.ClassNotFoundException: org.jetbrains.kotlin.gradle.dsl.KotlinCompile
😨melix
09/27/2022, 8:04 AMmelix
09/27/2022, 8:05 AMcompileOnly
dependency on the Kotlin plugin. It does this because we only want to react to the presence of the plugin, but then we need to access the types to be able to do something.melix
09/27/2022, 8:05 AMJavi
09/27/2022, 8:07 AMmelix
09/27/2022, 8:07 AMmelix
09/27/2022, 8:08 AMmelix
09/27/2022, 8:08 AMJavi
09/27/2022, 8:11 AMmelix
09/27/2022, 8:11 AMplugins {
alias libs.plugins.kotlin.jvm
alias libs.plugins.kotlin.kapt
alias libs.plugins.kotlin.allopen
id 'io.micronaut.build.internal.oraclecloud-example'
}
and this doesn't:
plugins {
id 'io.micronaut.build.internal.oraclecloud-example'
alias libs.plugins.kotlin.jvm
alias libs.plugins.kotlin.kapt
alias libs.plugins.kotlin.allopen
}
but because of classloadersmelix
09/27/2022, 8:11 AMmelix
09/27/2022, 8:11 AMClassNotFoundException
melix
09/27/2022, 8:27 AMmelix
09/27/2022, 8:43 AMbuildSrc
). Annoying.Vampire
09/27/2022, 9:05 AMJendrik Johannes
09/27/2022, 9:22 AMio-micronaut...
is loaded there and operates in this context. The Kotlin stuff if loaded on top only in the subproject loader. That explains for me why it is not seen - which would be what I expect (although I think it’s a shitty behaviour, if I am correct).melix
09/27/2022, 9:23 AMio.micronaut
plugin is loaded in buildSrc
Jendrik Johannes
09/27/2022, 9:24 AMit works if I put all plugins on my script classpath (viaThat would confirm it. “buildSrc” is always in the root.). Annoying.buildSrc
Vampire
09/27/2022, 9:24 AMVampire
09/27/2022, 9:25 AMbuildSrc
is even one level higher than root iircJendrik Johannes
09/27/2022, 9:26 AMVampire
09/27/2022, 9:27 AMmelix
09/27/2022, 9:27 AMmelix
09/27/2022, 9:27 AMSo that you have some "configure kotlin" class that you load from the thread context class loader in your plugin and that can then see the Kotlin classes?That would be extremely cumbersome to write the configuration code, basically using reflection
Vampire
09/27/2022, 9:28 AMloaded in the root.iirc that wouldn't work if buildSrc is involved as it is the parent of the root project class loader
Vampire
09/27/2022, 9:29 AMThat would be extremely cumbersome to write the configuration code, basically using reflectionNah, not with reflection, by loading your class from the lower class loader
Vampire
09/27/2022, 9:29 AMVampire
09/27/2022, 9:30 AMmelix
09/27/2022, 9:30 AMVampire
09/27/2022, 9:30 AMJendrik Johannes
09/27/2022, 9:34 AMIf plugin applied in root -> 'apply id("other-plugin") false' in root
When used through buildSrc -> Add dependency 'implementation("other.plugin:coordinates")' to "buildSrc/build.gradle"
melix
09/27/2022, 9:35 AMVampire
09/27/2022, 9:35 AMJendrik Johannes
09/27/2022, 9:36 AMmelix
09/27/2022, 9:36 AMmelix
09/27/2022, 9:39 AMmelix
09/27/2022, 9:39 AMmelix
09/27/2022, 9:39 AMVampire
09/27/2022, 10:01 AMtony
09/27/2022, 4:36 PMplugins {
id 'kotlin' version 'whatever' apply false
}
because it is indeed a classloader issue where my plugin couldn't see the kotlin classesJavi
09/27/2022, 4:38 PMkotlin
without jvm
, multiplatform
and so on, suffix, it is like applying a general one?Javi
09/27/2022, 4:38 PMkotlin
id plugintony
09/27/2022, 4:43 PMJendrik Johannes
09/28/2022, 6:19 AMJendrik Johannes
09/28/2022, 6:21 AMimplementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
in buildSrc/build.gradleCristianGM
09/28/2022, 7:10 AMCristianGM
09/28/2022, 7:11 AMCristianGM
09/28/2022, 7:15 AMCristianGM
09/28/2022, 7:17 AMVampire
09/28/2022, 9:10 AMVladimir Sitnikov
09/28/2022, 12:17 PMreflection
API to configure target plugins.
Even though it kind of defeats the reason to have compileOnly
, it might be viable if you do not need to use KotlinCompile
-like classes a lot.Vampire
09/28/2022, 12:23 PM