So I always struggle with the fact that plugin ext...
# community-support
t
So I always struggle with the fact that plugin extensions can only be evaluated once the module's
build.gradle.kts
is evaluated (i.e. in
afterEvaluate
). So if I'd like to have some kind of configurability for a build convention plugin so that I can decide whether or not certain plugins are applied, how would I do that? Or is this impossible? In plain words, an extension boolean property for convention-plugin to apply other-plugin when the extension property is set to
true
in the module's
build.gradle.kts
. Or is the only other way to extract that part of the configuration into a separate build convention plugin and apply it in the module's
build.gradle.kts
? Right now I try to group common configuration in "super convention plugins" that are applied to the specific module, but just now and then things get a little too heavy.
v
Don't have a property but a function in the extension and do the logic in the function of the extension.
☝️ 2
m
Would be cool to have this in the docs, everybody struggles with this
t
@Vampire So basically something like this?
Copy code
abstract class KotlinCommonExtension @Inject constructor(private val project: Project) {
    fun useCompose() {
        project.plugins.withId("com.android.base") {
            project.configureAndroidCompose()
        }
        project.plugins.withId("org.jetbrains.kotlin.multiplatform") {
            project.configureMultiplatformCompose()
        }
    }
}
(implementation snipped)
v
Besides that you should not use
project.plugins
(see its JavaDoc) but
project.pluginManager
, yes.
👍 1
t
the code above only runs configuration when those plugins are applied. your functions must also apply the plugins
t
Yes, these are applied as part of the super convention plugin. I have a super convention plugin for each module type, android library, kmp library, android app, desktop app, aso. They share common configuration (like all Kotlin-related configuration goes into my KotlinCommon convention plugin, all Android-related configuration goes into my AndroidCommon convention plugin) and the super convention plugins include the proper upstream base modules, i.e. com.android.application, com.android.library, ...
Nice, that seems to work, thanks!
👌 1