我是 Gradle 新手,正在尝试为我的 Spring Boot 多模块项目配置 Spotbugs。
在我的父母 build.gradle 中,
buildscript {
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${versionSpringBoot}"
}
}
plugins {
id 'com.github.spotbugs' version '1.6.8'
}
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'pmd'
apply plugin: 'jacoco'
dependencyManagement {
imports {
}
}
configurations{
}
sourceCompatibility = '15'
targetCompatibility = '15'
dependencies {
}
pmd {
consoleOutput = true
toolVersion = "${versionPmd}"
sourceSets = [sourceSets.main]
ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"]
}
spotbugs {
toolVersion = "${versionSpotBugs}"
sourceSets = [sourceSets.main]
}
jacoco {
toolVersion = "${versionJacoco}"
}
jacocoTestReport {
reports {
xml.enabled = true
}
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
}
Run Code Online (Sandbox Code Playgroud)
Spotbugs 不会在运行时运行
./gradlew 检查
构建配置的主要问题是您仅将 SpotBugs 插件应用于根项目。以下配置解决了这个问题(为了简洁,省略了与 SpotBugs 插件无关的配置):
\nplugins {\n // we don\xe2\x80\x99t need to *apply* the plugin to the root project, do we?\n id \'com.github.spotbugs\' version \'4.7.0\' apply false\n}\n\nsubprojects {\n apply plugin: \'java\'\n // this is the most important part, applying the plugin to the subprojects,\n // too:\n apply plugin: \'com.github.spotbugs\'\n\n spotbugs {\n toolVersion = \'4.2.2\'\n }\n\n tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {\n reports {\n xml.enabled = false\n html.enabled = true\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n使用此配置,./gradlew check还可以运行子项目的 SpotBugs 任务(使用 Gradle 6.8.3 进行测试)。
请注意,我\xe2\x80\x99ve 还做了一些其他更改:
\nsourceSets不需要的配置,并且无论如何都不起作用。我希望这有帮助。如果您\xe2\x80\x99 由于某种原因仍坚持使用旧的 SpotBugs 版本,请告诉我;在这种情况下,了解您使用的 Gradle 版本会有所帮助。
\n| 归档时间: |
|
| 查看次数: |
5266 次 |
| 最近记录: |