- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我一直在努力添加 SpotBugs到我目前正在处理的android项目。我设法让它工作,但我对它的设置方式并不过分兴奋。目前,配置位于我的 app/build.gradle 文件中,这使得该文件不易管理。
我想知道是否有 SpotBugs/Gradle 专家知道将配置拉出到单独文件中的方法。
这是我的 app/build.gradle(删除了样板):
buildscript {
repositories {
...
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
classpath 'io.fabric.tools:gradle:1.25.4'
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
}
}
plugins {
id 'com.gladed.androidgitversion' version '0.4.3'
id "com.github.spotbugs" version "1.6.2"
}
...
apply plugin: 'com.github.spotbugs'
apply from: '../config/quality/quality.gradle'
apply from: '../app/jacoco.gradle'
apply from: '../app/ktlint.gradle'
apply from: '../app/androidgit.gradle'
...
spotbugs {
toolVersion = '3.1.3'
ignoreFailures = false
effort = "min"
// This selects what level of bugs to report: low means low priority issues will be reported
// (in addition to medium+high), which corresponds to warning about everything.
// TODO: boost this to low once low priority issues are fixed.
reportLevel = "medium"
excludeFilter = new File("$project.rootDir/config/quality/spotbugs/android-exclude-filter.xml")
}
task spotbugs(type: com.github.spotbugs.SpotBugsTask, dependsOn: 'assemble', group: 'verification') {
classes = files("$projectDir.absolutePath/build/intermediates/app_classes/debug")
source = fileTree('src/main/java')
// Only one report format is supported. Html is easier to read, so let's use that
// (xml is the one that's enabled by default).
reports {
xml.enabled = false
html.enabled = true
}
classpath = files()
}
编辑
每当我尝试将 SpotBugs 从我的 app/build.gradle 中分离出来时,我都会遇到以下错误:
无法为类型为 org.gradle.api.Project 的项目“:app”获取未知属性“SpotBugsTask”。
这是我的 gradle 文件:
apply plugin: 'com.github.spotbugs'
dependencies {
checkstyle 'com.puppycrawl.tools:checkstyle:8.11'
spotbugs "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.2"
// spotbugs configurations.spotbugsPlugins.dependencies
// spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.8.0'
}
def qualityConfigDir = "$project.rootDir/config/quality";
def reportsDir = "$project.buildDir/reports"
check.dependsOn 'checkstyle'
task checkstyle(type: Checkstyle, group: 'Verification', description: 'Runs code style checks') {
configFile file("$qualityConfigDir/checkstyle/checkstyle-config.xml")
source 'src/main/java'
include '**/*.java'
exclude '**/model/**'
exclude '**/AppLogger.java'
reports {
xml.enabled = true
xml {
destination file("$reportsDir/checkstyle/checkstyle.xml")
}
}
classpath = files()
}
spotbugs {
toolVersion = '3.1.3'
ignoreFailures = false
effort = "min"
// This selects what level of bugs to report: low means low priority issues will be reported
// (in addition to medium+high), which corresponds to warning about everything.
// TODO: boost this to low once low priority issues are fixed.
reportLevel = "medium"
excludeFilter = new File("$project.rootDir/config/quality/spotbugs/android-exclude-filter.xml")
}
task spotbugs(type: SpotBugsTask, dependsOn: 'assemble', group: 'verification') {
classes = files("$projectDir.absolutePath/build/intermediates/app_classes/debug")
source = fileTree('src/main/java')
// Only one report format is supported. Html is easier to read, so let's use that
// (xml is the one that's enabled by default).
reports {
xml.enabled = false
html.enabled = true
}
classpath = files()
}
最佳答案
终于找到了解决办法。
我必须将以下内容添加到我在 app/build.gradle 文件中应用所有插件的部分:
project.extensions.extraProperties.set('SpotBugsTask', com.github.spotbugs.SpotBugsTask)
所以它最终看起来像这样:
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
classpath 'io.fabric.tools:gradle:1.25.4'
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
}
}
plugins {
id 'com.gladed.androidgitversion' version '0.4.3'
id "com.github.spotbugs" version "1.6.2"
}
// Workaround to be able to access SpotBugsTask from external gradle script.
// More info: https://discuss.gradle.org/t/buildscript-dependencies-in-external-script/23243
project.extensions.extraProperties.set('SpotBugsTask', com.github.spotbugs.SpotBugsTask)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'io.fabric'
apply plugin: 'spoon'
apply from: '../app/checkstyle.gradle'
apply from: '../app/jacoco.gradle'
apply from: '../app/ktlint.gradle'
apply from: '../app/androidgit.gradle'
apply from: '../app/spotbugs.gradle'
android {
...
我的 spotbugs.gradle 文件:
dependencies {
spotbugs configurations.spotbugsPlugins.dependencies
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.8.0'
}
def qualityConfigDir = "$project.rootDir/config/quality"
def reportsDir = "$project.buildDir/reports"
spotbugs {
toolVersion = "$spotbugs_version"
ignoreFailures = false
effort = "min"
// This selects what level of bugs to report: low means low priority issues will be reported
// (in addition to medium+high), which corresponds to warning about everything.
// TODO: boost this to low once low priority issues are fixed.
reportLevel = "medium"
excludeFilter = new File("$qualityConfigDir/config/quality/spotbugs/android-exclude-filter.xml")
}
tasks.register("spotbugs", SpotBugsTask) {
dependsOn 'assemble'
group = "verification"
classes = files("$projectDir.absolutePath/build/intermediates/app_classes/debug")
source = fileTree('src/main/java')
// Only one report format is supported. Html is easier to read, so let's use that
// (xml is the one that's enabled by default).
reports {
xml.enabled = true
xml {
destination file("$reportsDir/spotbugs/spotbugs.xml")
}
html.enabled = true
}
classpath = files()
}
关于android - 将 SpotBugs 添加到我的项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51191815/
由于 spotbugs 插件,在创建 aws-sdk-v2 jar 时构建失败。 重现错误的步骤:克隆最新版本的 aws-sdk-java-v2在终端中,转到目录并运行 mvn clean insta
我有这样的代码: public static MyObject forId(long myObjectId, Connection cxn) throws SQLException { try
我在 Eclipse IDE 中使用 Spotbugs 插件。我可以在整个项目上运行 Spotbugs,这给我的印象是该工具需要构建项目才能呈现其分析报告。 但是文档说它是一个静态分析工具。 所以,我
我正在尝试像下面这样使用 spotbugs-maven-plugin ... com.github.spotbugs spotbugs-maven-plugin
我有一个多项目 Gradle 设置,如下所示: RootProject | ---- ProjectA | ---- ProjectB | ---- P
我一直在努力添加 SpotBugs到我目前正在处理的android项目。我设法让它工作,但我对它的设置方式并不过分兴奋。目前,配置位于我的 app/build.gradle 文件中,这使得该文件不易管
我使用 SpotBugs Maven Plugin进行静态分析,我想从检查中排除一个目录。查看 spotbugs:check goal documentation , 似乎不可能配置插件是这样的方式。
SpotBugs 是 Findbugs 的继任者,通过静态分析来查找 Java 代码中的 bug。 下面我们主要是介绍 SpotBugs 在 idea 中的安装和使用 安装 Idea
本文将向您介绍 SpotBugs 实用程序项目,它可以帮助您发现代码中可能变成运行时错误的 Java“BUG模式”。 SpotBugs 入门 首先,让我们看看 SpotBugs 是如何工作的。此工具使
我有一个遗留的 maven 项目,想集成 FindBugs 继任者 SpotBugs 来创建所有问题的报告,但如果存在 High 仅限优先问题(目前)。 仅在特定阈值或不失败的情况下创建报告很容易。但
这是我的pom.xml: 4.0.0 de.stackoverflow.test HelloWorld 1.0-SNAPSHOT jar
我是一名构建工程师,我的开发团队在 Jdeveloper IDE 中开发代码。有没有办法直接将spotbugs集成到Jdeveloper中并找到bug? 最佳答案 对于 JDeveloper 12c,
我正在研究在 Java 中动态注入(inject) groovy 脚本。因此,在执行这些脚本之前,我想使用 SpotBugs 确保它们没有潜在的错误。 (静态代码分析器)。这是伪代码: Here it
如何为 Android 设置 SpotBugs? 我尝试关注 official documentation和 gradle plugin 的那个,但针对 Android 的设置不完整且令人困惑,并且无
简而言之:是否有用于 FindBugs/SpotBugs 过滤器文件的官方 DTD 或 XML 模式? 详细信息:在 FindBugs/SpotBugs 中,可以定义过滤文件,它们是 XML 文件。我
我正在尝试将 Maven Spotbugs 插件集成到我项目的 pom.xml 文件中,并使其在运行“mvn site”命令后在“项目报告”部分生成报告。我能够得到其他报告,例如 PMD、CPD 和
我正在努力解决以下问题:我想设置我的 ant 来编译 Java 源代码。一切正常,但我还想使用 Spotbugs/findpugs 分析工具。 所以手册中写道: 老实说,我不知道他们想从我这里得到
我想在我的android项目中使用spotbugs,但它失败并出现异常。运行任务:gradle->module->other->spotbugs 我有一个异常(exception): FAILURE:
对不起,我又挣扎了。所以taskdef工作正常,但我无法实际使用spotbugs。 所以我想检查代码 ant -Dpackage=einstieg 错误 并
我现在正在使用 FindBugs。我听说 FindBugs 现在已经过时了。 SpotBugs 是 FindBugs 的继承者。我想在我的 Jenkins 中安装 SpotBugs 插件。 我在可用插
我是一名优秀的程序员,十分优秀!