I am looking to create a custom plugin that configures Jacoco.
In my project build.gradle I apply the jaococ plugin and configure Jacoco (JacocoTaskExtension) for the ‘test’ task:
apply plugin:"jacoco"
test {
jacoco {
enabled = true
output = JacocoTaskExtension.Output.TCP_SERVER
}
}
This works fine. Now I want to move this configuration into a stand-alone custom plugin I am developing that can be applied to other projects.
public class MyPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
// TODO how do I define the jacoco DSL within the test task before applying the jacoco plugin?
// i.e. jacoco { enabled = true etc. }
project.getPluginManager().apply("jacoco");
}
}
I can’t figure out how to programatically define the jacoco (JacocoTaskExtension) extension DSL for the ‘test’ task. i.e. setting the jacoco.enabled and jacoco.output properties before the jacoco plugin is applied.
I tried updating the JacocoTaskExtension after the jacoco plugin was applied but it seems it’s too late at that point as the JacocoTaskExtension configuration has already generated the jacoco agent JVM args when the jacoco plugin is applied to the task.
Any ideas?