Slackbot
06/27/2023, 6:17 AMThomas Broyer
06/27/2023, 7:50 AMalias() will add the version as well; this is why Gradle 7.4 relaxed the syntax to allow the version to be used in subprojects when it has the same value as in the parent project: https://docs.gradle.org/7.4.2/release-notes.html#plugins-can-be-declared-with-a-version-in-a-subproject-in-more-casesThomas Broyer
06/27/2023, 7:51 AMplugins in my build logic pluginā? š¤Vampire
06/27/2023, 8:44 AMWithout version catalog plugins are usually declared with version and apply false.I wouldn't say "usually". If you want to centralize plugin versions wihtout version catalog, the usual way is to define the version in
pluginManagement { plugins { ... } } and then apply without version where you want it.
Declaring the plugin with apply false in the root project is usually used to overcome class loader issues.
You can define the version there too though instead.
Is it enough to apply the plugin and the version will be the one of the matching plug-in ID defined in my version catalog?The version catalog is just what it name says, a catalog of versions and coordinates to pick from. Just having something in the version catalog does not influence anything. The version is used nowhere and it is applied nowhere. In a "build logic plugin" you define the dependency / version in the build script of the project that builds that plugin as normal dependency and then you apply it without version in the plugin.
Aaron Ferguson
06/27/2023, 4:29 PMDaniele Segato
06/28/2023, 1:09 PMclass AndroidHiltConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
some of these plugins have to bring in other plugins
This is how Iām doing it right now:
pluginManager.apply("com.android.application")
The thing is that this syntax here does not allow me to pass a version.
while in my modules I used to do something like this:
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}
using version catalog
I now include my build logic plugins:
plugins {
id("my.buildlogic.android.application")
}
But the plugin I apply is versionless now.
I cannot use the same syntax in my plugin:
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
val hiltPlugin = libs.findPlugin("dagger-androidHilt").get()
plugins {
alias(hiltPlugin)
}
Because on the plugins { } I get this error:
Using āplugins(PluginDependenciesSpec.() -> Unit): Nothingā is an error. The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply<PluginType>() or apply(plugin = āidā) instead.and the other API (pluginManagement.apply) doesnāt accept a version. So basically, if I understood your answer: you are telling me, that I should do this in my main
build.gradle.kts
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
// etcā¦
}
is that correct?Thomas Broyer
06/28/2023, 1:12 PMdependencies {} of your plugin (add a dependency to the "plugin marker artifact")
Otherwise yes, use alias() ⦠apply false on the consumer side.Vampire
06/28/2023, 1:30 PMapply false, but as I also said above, define them as dependency in your build logic build, so for example gradle/build-logic/build.gradle.kts or buildSrc/build.gradle.kts, whatever your build logic build is.Daniele Segato
06/29/2023, 12:40 PM