我尝试将spotbug应用到一个大型开源项目elasticsearch上,该项目的结构非常复杂,通过将spotbug配置为 allprojects
在根目录下的build.gradle文件中。
问题是:它没有为所有子项目生成报告。
复制步骤
渐变版本:6.6.1
在您的计算机上安装java14。
从github克隆elasticsearch。
修改第一个 allprojects
在 build.gradle
在根目录下,如下所示:
plugins {
...
id "com.github.spotbugs" version "4.6.0"
}
// common maven publishing configuration
allprojects {
group = 'org.elasticsearch'
version = VersionProperties.elasticsearch
description = "Elasticsearch subproject ${project.path}"
apply plugin: "com.github.spotbugs"
spotbugs {
toolVersion = '4.1.4'
ignoreFailures = false
showStackTraces = true
showProgress = true
effort = 'default'
visitors = [ 'FindFinalizeInvocations','FindRoughConstants','FindRefComparison','FindUnrelatedTypesInGenericContainer','FormatStringChecker','DontCatchIllegalMonitorStateException','InfiniteRecursiveLoop','InheritanceUnsafeGetResource','Naming','SerializableIdiom','StaticCalendarDetector','DumbMethods' ]
maxHeapSize = '4g'
reportLevel = 'low'
}
}
编译源文件和测试文件
gradle clean classes testClasses -Dorg.gradle.java.home=/usr/lib/jvm/java-14-openjdk
执行SpotBug的任务
gradle spotbugsMain spotbugsTest -Dorg.gradle.java.home=/usr/lib/jvm/java-14-openjdk
计数xml报告
find . -path "*build/reports/spotbugs/*.xml" | wc -l # output: 22
结果
我注意到没有为某些子项目生成xml报告。例如,如下面的树所示,subproject client作为xml报告,但是x-pack没有。
.
├── ...
├── client
│ └── benchmark
│ ├── build
│ │ ├── ...
│ │ └── reports
│ │ └── spotbugs
│ │ └── main.xml
│ ├── build.gradle
│ ├── ...
│ └── src
│
└── x-pack
├── build.gradle
└── plugin
└── sql
├── build.gradle
├── other_sub_modules
└── src
然后,我将目录更改为子项目x-pack:plugin:sql,并修改了其 build.gradle
具体如下:
allprojects {
tasks.register("checkNoBwc") {
dependsOn tasks.withType(Test).matching { it.name.contains('bwc') == false }
}
apply plugin: "com.github.spotbugs"
spotbugs {
toolVersion = '4.1.4'
ignoreFailures = false
showStackTraces = true
showProgress = true
effort = 'default'
includeFilter = file("/home/xiaowen/Project/rbugs_experiments/build_projects/spotbugs-includeFilter.xml")
visitors = [ 'FindFinalizeInvocations','FindRoughConstants','FindRefComparison','FindUnrelatedTypesInGenericContainer','FormatStringChecker','DontCatchIllegalMonitorStateException','InfiniteRecursiveLoop','InheritanceUnsafeGetResource','Naming','SerializableIdiom','StaticCalendarDetector','DumbMethods' ]
maxHeapSize = '4g'
reportLevel = 'low'
}
}
在执行spotbug任务之后,我得到了带有bug示例的xml报告。
问题
只在根目录中配置spotbug时 build.gradle
,为什么子…子项目,如sql,被忽略?
如何通过修改覆盖所有子项目 build.gradle
是不是尽可能少?
更多信息:部分结果 gradle -q projects -Dorg.gradle.java.home=/usr/lib/jvm/java-14-openjdk
从中我们知道gradle成功地了解了sql的子项目。
| +--- Project ':x-pack:plugin:sql' - The Elasticsearch plugin that powers SQL for Elasticsearch
| | +--- Project ':x-pack:plugin:sql:jdbc' - JDBC driver for Elasticsearch
| | +--- Project ':x-pack:plugin:sql:qa' - Integration tests for SQL
| | | +--- Project ':x-pack:plugin:sql:qa:jdbc' - Integration tests for SQL JDBC driver
| | | | +--- Project ':x-pack:plugin:sql:qa:jdbc:multi-node' - Run SQL JDBC tests against multiple nodes
| | | | +--- Project ':x-pack:plugin:sql:qa:jdbc:no-sql' - Elasticsearch subproject :x-pack:plugin:sql:qa:jdbc:no-sql
| | | | +--- Project ':x-pack:plugin:sql:qa:jdbc:security' - Elasticsearch subproject :x-pack:plugin:sql:qa:jdbc:security
| | | | | +--- Project ':x-pack:plugin:sql:qa:jdbc:security:with-ssl' - Elasticsearch subproject :x-pack:plugin:sql:qa:jdbc:security:with-ssl
| | | | | \--- Project ':x-pack:plugin:sql:qa:jdbc:security:without-ssl' - Elasticsearch subproject :x-pack:plugin:sql:qa:jdbc:security:without-ssl
| | | | \--- Project ':x-pack:plugin:sql:qa:jdbc:single-node' - Elasticsearch subproject :x-pack:plugin:sql:qa:jdbc:single-node
| | | \--- Project ':x-pack:plugin:sql:qa:server' - Integration tests for SQL
| | | +--- Project ':x-pack:plugin:sql:qa:server:multi-node' - Run a subset of SQL tests against multiple nodes
| | | +--- Project ':x-pack:plugin:sql:qa:server:security' - Elasticsearch subproject :x-pack:plugin:sql:qa:server:security
| | | | +--- Project ':x-pack:plugin:sql:qa:server:security:with-ssl' - Elasticsearch subproject :x-pack:plugin:sql:qa:server:security:with-ssl
| | | | \--- Project ':x-pack:plugin:sql:qa:server:security:without-ssl' - Elasticsearch subproject :x-pack:plugin:sql:qa:server:security:without-ssl
| | | \--- Project ':x-pack:plugin:sql:qa:server:single-node' - Elasticsearch subproject :x-pack:plugin:sql:qa:server:single-node
| | +--- Project ':x-pack:plugin:sql:sql-action' - Request and response objects shared by the cli, jdbc and the Elasticsearch plugin
| | +--- Project ':x-pack:plugin:sql:sql-cli' - Command line interface to Elasticsearch that speaks SQL
| | +--- Project ':x-pack:plugin:sql:sql-client' - Code shared between jdbc and cli
| | \--- Project ':x-pack:plugin:sql:sql-proto' - Request and response objects shared by the cli, jdbc and the Elasticsearch plugin
暂无答案!
目前还没有任何答案,快来回答吧!