如何在自定义Gradle插件中配置Jacoco?
我正在编写一个自定义的Gradle插件,该插件应从我的自定义Gradle配置中统一抽象,该配置分布在多个Java项目中。为此,我通常会尝试找到
因此,我到了我想移动到插件。从build.gradle摘录看起来像这样:
jacocoTestReport {
reports {
xml.required = true
}
}
第一部分是可以管理的:检查插件是否已加载。
project.getPlugins().withType(JacocoPlugin.class, jacocoPlugin -> {
// configure it
})
但是,我坚持如何通过扩展方法实际配置插件。可用的唯一扩展名似乎是jacocopluginextension
。从那里开始,我看不到一种方法来添加Reports
从build.gradle添加部分。
除了我错过的扩展外,还有其他机制吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“ jacocotestReport”实际上是一项任务,因此您可以像这样进行配置:
如果您想深入挖掘,则是
'jacocoTestReport' is actually a task, so you can configure it like this:
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.