我一直在努力将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/@R_595_5404@.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/23243project.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/@R_595_5404@.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添加到我的项目全部内容,希望文章能够帮你解决android-将SpotBugs添加到我的项目所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)