Sergej Koščejev
06/26/2024, 1:09 PMplugins.withType<JavaBasePlugin> { ... }
and
plugins.withId("java-base") { ... }
and
pluginManager.withPlugin("java-base") { ... }
?Niels Doucet
06/26/2024, 1:14 PMwithType call returns a collection, so that might potentially affect multiple applied plugins (either immediately, or deferred, which is true for all cases).Vampire
06/26/2024, 1:40 PMwithType could not really affect multiple applied plugins, as every plugin can only applied once and every attempt after that is a NOP.Vampire
06/26/2024, 1:41 PMgetPlugins() (which you use by plugins.) you see, that even if not deprecated you should not use it at all, but pluginManager instead.Vampire
06/26/2024, 1:42 PMplugins.withType concretely is mainly when matching 3rd party plugins because depending on class loader in effect where it is called, you might get different class instances and so not match the plugin you intend.Vampire
06/26/2024, 1:43 PMpluginManager.withPlugin and you are on the safe side. 🙂Sergej Koščejev
06/26/2024, 1:43 PMVampire
06/26/2024, 1:44 PM...withType<...> { ... } but always ...withType<...>().configureEach { ... }.
Currently it is mainly making a difference with task containers to not break task-configuration avoidance, but in case another container gets treated lazily in the future, you are already on the safe side.Sergej Koščejev
06/26/2024, 1:45 PMThomas Broyer
06/26/2024, 2:35 PMwithType and "multiple applied plugins", you could pass a base class or an interface that could be extended/implemented by more than one plugin (e.g. all plugins from the Android Gradle Plugin extend from com.android.build.gradle.BasePlugin).
Kind of an edge case anyway.Vampire
06/26/2024, 2:45 PM