This message was deleted.
# community-support
s
This message was deleted.
t
Using version catalog,
alias()
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-cases
šŸ‘ 1
Now what do you mean by ā€œi cannot use
plugins
in my build logic pluginā€? šŸ¤”
v
Without 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.
šŸ‘ 1
a
yeah I wouldn't say usual is apply false either...the default is true for a reason...that's the actual usual imo
d
Sorry for the late reply. I’m migrating to build logic to setup my project, so I have plugins like this:
Copy code
class 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:
Copy code
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:
Copy code
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
}
using version catalog I now include my build logic plugins:
Copy code
plugins {
    id("my.buildlogic.android.application")
}
But the plugin I apply is versionless now. I cannot use the same syntax in my plugin:
Copy code
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
Copy code
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?
t
If your plugin depends on those other plugins, then add them as
dependencies {}
of your plugin (add a dependency to the "plugin marker artifact") Otherwise yes, use
alias() … apply false
on the consumer side.
v
Yeah, as Thomas said, to not use the
apply 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.
d
Thank you everyone
šŸ‘Œ 1