Callum Rogers
04/23/2025, 2:01 PMMartin
04/23/2025, 2:04 PMMartin
04/23/2025, 2:05 PMMartin
04/23/2025, 2:07 PMbeforeProject{}
to apply a plugin to all projects
https://github.com/gradle/gradle/issues/22514#issuecomment-2099179052Martin
04/23/2025, 2:08 PMgradle.lifecycle.beforeProject {
pluginManager.apply("java")
}
gradle.lifecycle.afterProject {
println("Is it java? ${extensions.findByName("java")}")
}
Callum Rogers
04/23/2025, 2:08 PMMartin
04/23/2025, 2:09 PMCallum Rogers
04/23/2025, 2:13 PMMartin
04/23/2025, 2:14 PMCallum Rogers
04/23/2025, 2:14 PMCallum Rogers
04/23/2025, 2:16 PMMartin
04/23/2025, 2:18 PMMartin
04/23/2025, 2:18 PMVampire
04/23/2025, 2:23 PMcom.company.base
plugin that does stuff that should be done in every project.
The com.company.base
plugin verifies that the settings plugin is applied (via a boolean in a shared build service that the settings plugin sets to true
) and the settings plugin verifies that in each and every project the com.company.base
plugin is applied.
This way I ensure that if any project applies any plugin of the convention plugins, all projects apply any of the convention plugins and the settings plugin is also there to do its work.
Previously I had the settings plugin apply the base plugin to all projects that do not have it automatically. (With conventional ways, still on Gradle 7.x mainly here for reasons 😞) But that had other problems, as soon as the base plugin added a 3rd party plugin that uses afterEvaluate
as the time those were applied were at a stage where afterEvaluate
is no longer allowed.Callum Rogers
04/23/2025, 2:28 PM