Hey everyone! I just wanted to quickly check wheth...
# community-support
k
Hey everyone! I just wanted to quickly check whether my own understanding is correct. In a multi-project build, I'm trying to configure plugins when they are applied to subprojects (I understand that using
subprojects { ... }
is bad, but for a quick and dirty experiment, I hope I'm forgiven 😉). There are two ways that I see floating around:
pluginManager.withPlugin
and
plugins.withType
. Other than using different criteria to identify the applied plugin, are these two equivalent? It seems that they might be (if I understand the documentation correctly), but the fact that one method is associated with
PluginManager
and the other one with
PluginContainer
gives me pause. In addition, there is also
plugins.withId
, which, I guess, would then also be equivalent to
pluginManager.withPlugin
? If all of these are equivalent, is there a reason to prefer one over the other -- e.g. one being "the old way, which might get deprecated in the future"?
m
I would use
pluginManager.withPlugin()
to err on the safe side of things. I think this is the vetted way
The project isolation way is to do this in
settings.gradle.kts
:
Copy code
// settings.gradle.kts
include("sub1")
include("sub2")

gradle.lifecycle.beforeProject {
    apply(plugin = "base")
    repositories {
        mavenCentral()
    }
}
Copy code
While not deprecated, it is preferred to use the methods of this interface or the plugin manager than use the plugin container.
k
Yeah, if I remember correctly,
pluginManager.withPlugin
is what I found in the official documentation as well. Thanks for pointing me to the soft deprecation Javadoc; I did see the
plugins
methods used by big Gradle contributors in some GitHub issues, and figured that one method might be newer.
👍 1