Adam S
01/13/2024, 11:05 AMJoffrey
01/13/2024, 11:09 AMdynamic
wouldn't help you. You would need to at least have an instance at runtime, and then you could have the "dynamic" aspect of it by using reflection (although it's not ideal if course)Adam S
01/13/2024, 11:20 AMsettings.gradle.kts
2. BCVSettingsPlugin applies itself (BCVPlugin) to every subproject
3. if a subproject has the Kotlin KMP plugin applied, then BCVProjectPlugin reacts to it (so the KGP classes should be present)
4. however, while BCVProjectPlugin can see that Project has an extension with type org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainer
it fails because KotlinTargetsContainer class isn't present.
The workaround is to add KGP to the settings.gradle.kts
classpath, which isn't ideal. It's unusual and non-standard and annoying to maintain and document.
I think Gradle (sometimes?) isolates plugins classpaths, so even though BCVProjectPlugin is reacting to KGP inside settings.gradle.kts
, that doesn't automatically inherit KGP's classpath. However, when BCVProjectPlugin is applied as to a project the classpath for the whole buildscript is present.Adam S
01/13/2024, 11:23 AMephemient
01/13/2024, 8:36 PMdynamic
would only be possible via reflection (which is what Groovy does, or Gradle Kotlin DSL's withGroovyBuilder
)ephemient
01/13/2024, 8:39 PMdmitriy.novozhilov
01/13/2024, 10:31 PMAdam S
01/13/2024, 11:25 PMwithGroovyBuilder {}
works. It's a bit ugly but it's probably more stable than my custom dynamic typing.
Adding KGP to the root project (with apply false
) doesn't make a difference though, I still see An exception occurred ... Type org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension not present
when BCVProjectPlugin runs and reacts to KGP. It's something weird where Gradle isn't 'updating' the classpath when a settings-plugin applies a project-plugin.ephemient
01/14/2024, 12:07 AMAdam S
01/14/2024, 11:08 AMbuild.gradle.kts
I can access all classes from the plugins applied to that buildscript.
When I write a custom Gradle plugin I can add a compileOnly dependency on KGP and react to KGP. I expect that the KGP class files are there at runtime. This works sometimes, but not always, and the behaviour is inconsistent. Sometimes it can be worked around by applying KGP to the root build.gradle.kts
, but for whatever reason that's not working (the KGP classes are missing) when my custom plugin is applied to a build.gradle.kts
but from inside settings.gradle.kts
...Adam S
01/14/2024, 11:10 AMAdam S
01/14/2024, 11:11 AMephemient
01/14/2024, 12:54 PM