What I am trying to achieve in my plug-in is to simplify the following:
project.allprojects {
new EarConfigurator(it).configure()
new WarConfigurator(it).configure()
new JarConfigurator(it).configure()
new RepoConfigurator(it).configure()
new VersionConfigurator(it).configure()
etc
}
I have to run all the configurations, because this project is a corporate plug-in for all company projects. These company projects projects can vary from one to many jars ears and wars.
It’s still not clear for me what you want to achieve, but how about creating class which implements Plugin<Project>?
for exsample…
public class MyPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
new EarConfigurator(project).configure();
// ... and more
}
}
and its build script…
allprojects {
apply plugin: 'your-plugin-id'
}
This class and build script will lead you to achieve your requirement.
That is exactly what I am doing. I have a plug-in and in the I am running the project.allprojects:
public class BuildDefaultsPlugin implements Plugin<Project> {
void apply(Project project) {
project.allprojects {
new EarConfigurator(it).configure()
new WarConfigurator(it).configure()
new JarConfigurator(it).configure()
new RepoConfigurator(it).configure()
new VersionConfigurator(it).configure()
}
}
}
If I understand correctly, you’d probably make each of your ‘Configurator’ classes plugins and just apply each one (e.g., project.apply(plugin: EarConfigurator)). I’d probably make BuildDefaultsPlugin only apply to one project and put the allprojects {} in the build script. That would make it easier to compose plugins.