I am writing a custom Gradle plugin which shall unifiedly abstract from my custom gradle configurations which are spread across multiple Java projects. For this purpose, I generally try to find fitting extensions for the various tasks that need custom configuration.
So, I got to the point where I wanted to move my JaCoCo configuration to the plugin. The excerpt from build.gradle looks like this:
jacocoTestReport {
reports {
xml.required = true
}
}
The first part is manageable: check if the plugin is loaded.
project.getPlugins().withType(JacocoPlugin.class, jacocoPlugin -> {
// configure it
})
However, I am stuck with how to actually configure the plugin via an extension method. The only extension that is available seems to be JacocoPluginExtension
. From there, I don't see a way how to add the reports
part from build.gradle.
Is there some other mechanism besides extensions that I missed?
'jacocoTestReport' is actually a task, so you can configure it like this:
proj.tasks.getByName("jacocoTestReport", {
reports {
xml.required = true
}
})
If you'd like to dig deeper, it's class is JacocoReport , which has a JacocoReportsContainer reports property, so you may use type safe property getters / setters from there, but IMHO the above solution is more like build.gradle, so it's more readable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.