PMD,checkstyle和findbugs android设置

PMD,checkstyle和findbugs android设置,第1张

概述如何使用最新版本的gradle为 Android项目设置PMD,Findbugs和Checkstyle静态代码分析工具?我尝试了几件事,但我没有设法让它们起作用. 谢谢 Checkstyle / PMD 有一个很好的插件,你可以用于checkstyle和pmd.只需添加 buildscript { repositories { // ... } depend 如何使用最新版本的gradle为 Android项目设置PMD,FindBUGs和Checkstyle静态代码分析工具?我尝试了几件事,但我没有设法让它们起作用.

谢谢

解决方法 Checkstyle / PMD

有一个很好的插件,你可以用于checkstyle和pmd.只需添加

buildscript {    repositorIEs {        // ...    }    dependencIEs {        // ...        classpath 'com.androID.tools.build:gradle:1.2.3'        // Enables checkStyle and pmd gradle support for androID modules        classpath 'com.noveogroup.androID:check:1.1.2'    }}

到您的全局gradle.build并在您的模块中使用它,如下所示:

apply plugin: 'com.noveogroup.androID.check'check {    abortOnError false    checkstyle {        config "$rootProject.rootDir/path/to/your/checkstyle.xml"    }    pmd {        config "$rootProject.rootDir/path/tp/your/pmd-ruleset.xml"    }}

或任何这些配置:

// configuration is optionalcheck {    // skip source code checking or not,false by default    skip true/false    // fails build if code style violation is found,false by default    abortOnError true/false    checkstyle {        // skip Checkstyle,false by deafult        skip true/false        // fails build if Checkstyle rule violation is found,false by default        abortOnError true/false        // configuration file        config project.file('path/to/checkstyle.xml')        // configuration resource        // see http://gradle.org/docs/2.2/release-notes#sharing-configuration-files-across-builds        config resources.text.fromfile(soMetask)        // configuration path        config 'path/to/checkstyle.xml'        // predefined configurations: easy and hard        config easy()        config hard()        // plugin find configuration file in project.file('config/checkstyle.xml') by default        // if there are no configuration file,easy() configuration will be used    }    pmd {        // the same configuration as for Checkstyle        // plugin find configuration file in project.file('config/pmd.xml') by default        // if there are no configuration file,easy() configuration will be used    }}

Here你可以找到该插件的主页和源代码.

FindBUGs的

//更新//

noveogroup(1.2.3)的最新插件现在也支持findBUGs.所以你可以像checkstyle或pmd一样自定义它:

// configuration of FindBUGs checkerfindBUGs {  // the same configuration as for Checkstyle  // by default plugin finds configuration file in <rootProject>/config/findBUGs.xml,// after that in <project>/config/findBUGs.xml and if there are no configuration  // file,easy() configuration will be used.}

//更新结束//

我使用以下gradle脚本片段运行findBUGs检查,您将其添加到模块的build.gradle中:

apply plugin: 'findBUGs'task customFindBUGs(type: FindBUGs) {    ignoreFailures = true    effort = "default"    reportLevel = "medium"    classes = files("$project.buildDir/intermediates/classes")    excludeFilter = file("$rootProject.rootDir/config/findBUGs/exclude.xml")    source = filetree('src/main/java/')    classpath = files()    reports {        xml.enabled = false        xml.withMessages = true        HTML.enabled = !xml.isEnabled()        xml.destination "$project.buildDir/outputs/findBUGs/findBUGs-output.xml"        HTML.destination "$project.buildDir/outputs/findBUGs/findBUGs-output.HTML"    }}// UPDATE: renamed the task to customFindBUGs and made it automatically be called when build is calledbuild.dependsOn customFindBUGs

我的exclude.xml如下所示:

<FindBUGsFilter>    <Match>       <Class name="~.*R$.*"/>    </Match>    <Match>        <Class name="~.*Manifest$.*"/>    </Match>    <Match>        <Class name="~.*_"/>    </Match></FindBUGsFilter>

而最后一项检查用于省略AndroIDAnnotations生成的类,您很可能不会使用此检查…

之后我就可以执行任务了

./gradlew customFindBUGs// or it is also included in the build task like the checks,too./gradlew build
总结

以上是内存溢出为你收集整理的PMD,checkstyle和findbugs android设置全部内容,希望文章能够帮你解决PMD,checkstyle和findbugs android设置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1135690.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存