I am working on a collection of plugins for building our software’s release bundle. One of the plugins is responsible for building fat JARs of our software. The other plugin is responsible for building the bundle itself, which contains the fat JAR among other things. Each plugin is responsible for creating multiple tasks and has multiple configuration parameters.
I have seemingly successfully built the fat JAR plugin, but the release plugin is unable to properly configure and access the tasks created by the fat JAR plugin. I was creating the tasks for the fat JAR extension inside an afterEvaluate block, but since the release plugin needs access to items that are calculated inside that block, it prevents me from accessing it.
Is there some way to configure a plugin using an extension without resorting to an afterEvaluate block? I tried DomainObjectCollection.whenObjectAdded, but it runs its closure when the extension object is first attached, not once it’s configured.
public class FatJarPlugin implements Plugin<Project>
{
@Override
void apply(final Project p)
{
// extract the test data from the DSL
p.extensions.fatJars = p.container(FatJarExtension) { final String name ->
return p.gradle.services.get(Instantiator).newInstance(FatJarExtension, name)
}
p.afterEvaluate {
p.extensions.fatJars.each { final FatJarExtension fj ->
// build tasks
fj.task = jarTask
}
}
}
}
// prior version of Release plugin was a task
public class Release extends Zip
{
public void info(final Closure info)
{
this.project.plugins.withType(FatJarPlugin) {
this.project.farJars {
testJar {
// configuration
}
}
}
this.project.afterEvaluate {
final Task jarTask = this.project.fatJars['testJar'].task
// access output.files property of jarTask
// FIXME: this doesn't work as the afterEvaluate in FatJarPlugin
// hasn't been executed yet
}
}
}