【发布时间】:2021-09-08 14:42:35
【问题描述】:
我正在使用带有 Gradle 的 Spotbugs。
我最近从 Maven 迁移到 Gradle,然后我意识到两个构建器工具中的同一个插件之间存在许多差异...
例如,我想查看带有错误结果的 Spotbugs GUI...在 Maven 中它非常简单。在 Gradle 中,Spotbugs 生成两个任务,每个文件夹(主要和测试)一个。这就是为什么有两个报告(main.xml和test.xml),完全阻碍了GUI的展示。
我正在做一些变通方法来显示两个带有两个报告结果的 GUI。 但是我在另一个任务中调用带有参数的任务时遇到了一些麻烦......我正在做的事情看起来像这样:
task spotbugsViewReports {
def reports = ['main', 'test']
for(String report : reports) {
def name = "spotbugsView_${report}"
task (name)(type: Exec) {
commandLine "java", "-jar", "${buildDir}/unpacked/dist/spotbugs-4.4.0/lib/spotbugs.jar"
args '-loadBugs', "${buildDir}/reports/spotbugs/${report}.xml"
}
}
doLast {
dependsOn 'spotbugsView_main'
dependsOn 'spotbugsView_test'
}
}
但它不起作用。有人可以帮我吗?
为了展示解决 spotbugs 与 Maven 插件不相等的完整和详尽的工作,下面是完整的解决方法:
task spotbugsGui {
finalizedBy 'spotbugsUnzip'
}
task spotbugsUnzip(type: Copy) {
def zipFile = file(project.configurations.artifact.find {
it.name.startsWith("spotbugs")
})
def outputDir = file("${buildDir}/unpacked/dist")
from zipTree(zipFile)
into outputDir
finalizedBy 'spotbugsRegisterGui'
}
task spotbugsRegisterGui {
def reports = ['main', 'test']
for(String report : reports) {
tasks.create("spotbugsExecGui_${report}", Exec) {
commandLine "java", "-jar", "${buildDir}/unpacked/dist/spotbugs-4.4.0/lib/spotbugs.jar"
args '-loadBugs', "${buildDir}/reports/spotbugs/${report}.xml"
}
}
finalizedBy 'spotbugsExecGui'
}
task spotbugsExecGui {
dependsOn 'spotbugsExecGui_main'
dependsOn 'spotbugsExecGui_test'
}
【问题讨论】:
标签: java maven gradle groovy spotbugs