我有一个多项目 Gradle 设置,如下所示:
RootProject
|
---- ProjectA
|
---- ProjectB
|
---- ProjectC
我想将 SpotBugs 应用于我的所有项目。
在每个项目中执行以下操作都明确有效。
例如,ProjectA
的 build.gradle
中的以下内容:
plugins {
id 'com.github.spotbugs' version '1.6.9'
}
spotbugs {
ignoreFailures = true
effort = 'min'
showProgress = true
reportLevel = 'medium'
// Only run spotbugs directly as too slow to run as CI.
// Will still run spotbugs when called like "gradlew spotbugsMain"
sourceSets = []
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
但是,我不想在所有项目的 build.gradle
文件中复制此代码。
如何将其提取到 RootProject
的构建文件中。
示例,在以下 block 内:
configure(subprojects.findAll {it.name != 'SomeProjectToIgnore'}) {
// how to configure spotbugs here ?
}
按原样移动 block 是行不通的。
最佳答案
您可以通过以下方式在根项目的 build.gradle 中配置 Spotbug:
buildscript {
repositories {
maven { url 'maven repository url' }
}
dependencies {
classpath group: 'gradle.plugin.com.github.spotbugs', name: 'spotbugs-gradle-plugin', version: '1.6.5'
}
}
allprojects {
apply plugin: 'com.github.spotbugs'
dependencies {
compileOnly group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: '3.1.8'
spotbugsPlugins group: 'com.h3xstream.findsecbugs', name: 'findsecbugs-plugin', version: '1.8.0'
}
spotbugs {
toolVersion = '3.1.8'
sourceSets = [ sourceSets.main ]
}
}
关于java - 用于多项目设置的 Spotbugs 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54585340/