Javi
03/22/2022, 11:01 AMmelix
03/22/2022, 11:28 AMFleshgrinder
03/22/2022, 11:41 AMgradle.beforeProject
and within it we can auto-register (especially with withPlugin
) things on the project without breaking isolation (at least so far, not sure what changes are upcoming).
What's missing from settings plugins is the generation of accessors for extensions etc. This makes them tedious to use for global configuration.Vampire
03/22/2022, 11:56 AMThere are still situations where one needs a global thing that child things can access
Sounds like the need for a shared build service
Fleshgrinder
03/22/2022, 12:06 PMJavi
03/22/2022, 12:32 PMJavi
03/22/2022, 12:35 PMChris
03/22/2022, 1:04 PMallprojects {
afterEvaluate { Project p ->
if (p.getPlugins().hasPlugin(BasePlugin)) {
assert p.getPlugins().hasPlugin(BaseConvention)
}
}
}
where the BaseConvention is my convention plugin and BasePlugin is the Gradle one.Chris
03/22/2022, 1:06 PMproject.afterEvaluate(p -> p.getPlugins().configureEach(plugin -> {
Collection<Class<? extends ConventionPlugin>> conventions = KNOWN_CONVENTIONS.get(plugin.getClass());
if (conventions != null && conventions.stream().noneMatch(convention -> project.getPlugins().hasPlugin(convention))) {
throw new IllegalStateException("Cannot apply " + plugin.getClass() + " directly. You must use a registered convention plugin: " + conventions);
}
}));
where ConventionPlugin
is my own invention:
public interface ConventionPlugin<T, P extends Plugin<? extends T>> extends Plugin<T> {
Class<P> isConventionFor();
}
Chris
03/22/2022, 1:06 PMstatic {
for (ConventionPlugin<?, ?> conventionPlugin : ServiceLoader.load(ConventionPlugin.class, BaseConvention.class.getClassLoader())) {
KNOWN_CONVENTIONS.computeIfAbsent(conventionPlugin.isConventionFor(), k -> new ArrayList<>()).add(conventionPlugin.getClass());
}
}