gpt4 book ai didi

android - 获取 Android gradle 插件和 checkstyle 一起工作/命令行使用

转载 作者:IT老高 更新时间:2023-10-28 22:16:40 30 4
gpt4 key购买 nike

我正在评估新的基于 gradle 的构建系统重现我们当前基于 ant 的构建过程的能力,作为一个 gradle 初学者,我未能让 checkstyle 与 android gradle 插件一起运行。

环境:

  • gradle 1.6 在标准 java 项目上运行良好(包括 checkstyle 检查目标)

  • 最新的 android SDK(22.0.1 带有平台工具和构建工具 17)

  • 没有eclipse,没有android studio,只有我可爱的终端

症状:

目标项目是https://github.com/nibua-r/LigoTextDemo我成功地使用 gradle 构建了它,但是如果我天真地将 apply plugin: checkstyle 添加到我的 build.gradle:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
apply plugin: 'checkstyle'

android {
buildToolsVersion '17'
compileSdkVersion 15
testBuildType 'debug'

defaultConfig {
versionCode = 1
versionName = '1.0'
minSdkVersion 12
targetSdkVersion 15
}

buildTypes {
debug {
packageNameSuffix = '.debug'
}
}
}

然后 gradle check 甚至不会提示找不到 checkstyle.xml 文件(在默认的 config/checkstyle 位置)和返回:

:check UP-TO-DATE

BUILD SUCCESSFUL

需要什么:

首先,我只需要一个正在运行的 checkstyle 目标。然后,我需要自动运行 checkstyle 作为编译的依赖项(但首先让 chekstyle 目标启动并运行)。

假设:

这可能与以下事实有关(来自 [用户指南][1]):

The Android plugin […] uses its own sourceSets

但我没有足够的 gradle-efficient 来理解我在那里缺少什么。请gradle大师用您宝贵的知识赐教!

最佳答案

我使用以下脚本获得了 pmd、findbugs 和 checkstyle 与 Gradle 1.12 android 插件 0.12.+ 一起使用:

apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'

check.dependsOn 'checkstyle', 'findbugs', 'pmd'

task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/quality/checkstyle/checkstyle.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'

classpath = files()
}

task findbugs(type: FindBugs) {
ignoreFailures = true
effort = "max"
reportLevel = "high"
excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml")
classes = files("$project.buildDir/intermediates/classes/")

source 'src'
include '**/*.java'
exclude '**/gen/**'

reports {
xml {
destination "$project.buildDir/reports/findbugs/findbugs.xml"
xml.withMessages true
}
}

classpath = files()
}

task pmd(type: Pmd) {
ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml")
ignoreFailures = true
ruleSets = ["basic", "braces", "strings"]

source 'src'
include '**/*.java'
exclude '**/gen/**'

reports {
xml.enabled = true
html.enabled = false
}
}

在命令行中运行 gradle build 将运行所有代码质量插件并在 app/build/reports/ 中生成 xml 报告,然后可供查看或解析CI 工具。

关于android - 获取 Android gradle 插件和 checkstyle 一起工作/命令行使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17050654/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com