android - Android Studio 的最小工作 SpotBugs 设置
问题描述
如何为 Android 设置 SpotBugs?
我尝试遵循官方文档和gradle plugin的文档,但 Android 的设置不完整且令人困惑,并且不起作用。
我尝试了以下设置。
build.gradle(项目):
buildscript {
repositories {
// ...
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
// ...
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.4"
}
}
build.gradle(应用程序):
//...
apply plugin: "com.github.spotbugs"
android {
// ...
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
}
// ...
spotbugs {
toolVersion = "3.1.3"
ignoreFailures = true
reportsDir = file("$project.buildDir/findbugsReports")
effort = "max"
reportLevel = "high"
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
// What do I need to do here?
}
我尝试使用 运行它./gradlew spotbugsMain
,但缺少 gradle 任务。
我应该手动添加任务吗?我怎么做?
你能告诉我一个 Android 项目的最小工作设置的例子吗?
解决方案
我做了一些测试,我设法让它像这样工作:
1)将sourceSets
声明移到android
块外。留空,它只是用于spotbugsMain
任务生成,不会影响全局 Android 构建。
android {
// ...
}
sourceSets {
main {
java.srcDirs = []
}
}
2)保留你的spotbugs
块并配置这样的SpotBugsTask
任务:
tasks.withType(com.github.spotbugs.SpotBugsTask) {
classes = files("$projectDir.absolutePath/build/intermediates/classes/debug")
source = fileTree('src/main/java')
}
它将在app/build/findbugsReports
重要的 :
它只适用于./gradlew build
命令,./gradlew spotbugsMain
不能工作,因为必须先构建项目
您可以解决添加assemble
依赖项的问题:
tasks.withType(com.github.spotbugs.SpotBugsTask) {
dependsOn 'assemble'
classes = files("$projectDir.absolutePath/build/intermediates/classes/debug")
source = fileTree('src/main/java')
}
推荐阅读
- javascript - D3.js 条形图根据数据的重量或值生成条形颜色
- angular - 尝试从 Firebase Firestore 获取集合时,“类型 '{}' 上不存在属性 'map'”
- c# - System.Linq.Enumerable+WhereSelectArrayIterator 与 List 上的 IEnumerable.Except()
- php - PHP preg_match_all 在比赛之间获取信息
- html - 将 flexbox 项目推送到桌面视图的右侧
- javascript - 警告:包装外部组件时的未知道具”
- dialogflow-es - Dialogflow V2 - 自定义上下文
- python - 这种排序有名称吗?什么样的数据对排序有效?
- html - 使用填充与高度(使用vh)与最小高度定义网页中部分高度的最佳实践是什么
- java - 与 AWS Dynamodb 集成的微服务应用程序中的 BeanCreationException