The purpose of the plugins
block in settings.gradle
is only to define default versions. Only the declaration in a project’s plugins
block causes the resolution and addition to the buildscript’s classpath (but you can omit the version).
You would need the following to use a settings.gradle
to specify default versions (noting that the plugins
block need not be in the same project as the conditional, as long as it’s in the plugins
block of a parent project. The end result is duplication of the plugins block (but maybe without versions) in the project:
// settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
}
plugins {
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
}
// build.gradle
plugins {
id 'com.github.johnrengelman.shadow' apply false
}
if (something) {
apply plugin: 'com.github.johnrengelman.shadow'
}
However, there is also technically nothing that requires you to do anything with the plugins themselves (just the repository if you need something special) in settings.gradle
. It is equally valid to specify all plugin information in the root project, and then conditionally apply them anywhere else in the build. i.e.:
// build.gradle
plugins {
id 'com.github.johnrengelman.shadow' version '5.2.0' apply false
}
// subproject/build.gradle
if (something) {
apply plugin: 'com.github.johnrengelman.shadow'
}
There’s also technically no value in caring about the plugins
block in the meta-plugin case. You can only conditionally apply plugins that are on the classpath. The plugins block puts them on the classpath, but you can decide to not apply them. They’re all going to be on the classpath of the buildscript anyway (and that’s inherited by subprojects), so you might as well just define them all as dependencies in meta-plugin case and then conditionally apply them, not worrying at all about the plugins
block.