java - 多项目设置的 Spotbugs 配置
问题描述
我有一个多项目 Gradle 设置,如下所示:
RootProject
|
---- ProjectA
|
---- ProjectB
|
---- ProjectC
我想将 SpotBugs 应用于我的所有项目。
在每个项目中明确执行以下操作。
例如,以下build.gradle
内容ProjectA
:
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
的构建文件中。
例如,在以下块内:
configure(subprojects.findAll {it.name != 'SomeProjectToIgnore'}) {
// how to configure spotbugs here ?
}
按原样移动块不起作用。
解决方案
您可以通过以下方式在根项目的 build.gradle 中配置 spotbugs:
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 ]
}
}
推荐阅读
- c# - 为什么一个命令只有一个 { get; set } 哪些其他参数指定了支持字段?
- node.js - MongooseError:`openUri()` 的`uri` 参数必须是字符串,得到“未定义”
- java - sendRedirect(test.jsp) 和 sendRedirect(/test.jsp) 的区别
- python - 如何在 Django 模板语言中优雅地表示负美元金额?
- python - 有没有办法用python修改一个url上的json文件
- grpc - gRPC-go 服务器变得无响应并在一段时间后开始备份请求
- javascript - React 状态值在通过 console.log() 打印时显示,但不在网页上
- html - 为什么添加不透明度会破坏 3D CSS 动画?
- netlogo - 在 NetLogo 中存储和调用策略的输出
- python - 有没有办法将输入变成列表?