【问题标题】:Google checkstyle configuration is failing on an Android projectGoogle checkstyle 配置在 Android 项目上失败
【发布时间】:2015-11-25 18:57:19
【问题描述】:

我正在尝试在 Android 项目中使用 Checkstyle。我认为 Google 的 Java 编码约定会很好用。解析此文件时出现错误:

https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml

我在堆栈溢出时查看过此错误,并且之前出现过一次,How to compile project with Google Checkstyle rules with gradle?

似乎错误是使用 gradle 时下拉了旧版本的 checkstyle。所以我的问题是,是否只有一个旧的 checkstyle 配置文件可以使用,它是为 gradle 下拉的当前版本的 checkstyle 制作的?我是否应该为 Android 项目使用 Google 的 Java 指南?是否有更好的默认文件可供使用?我真的不想将新版本的 checkstyle 导入到我的项目中,如另一个 SO 问题的答案中所述。

【问题讨论】:

  • 看看我的config。他们根据我的要求捆绑了 google_check,所以我可以这样做。
  • 问题不是很清楚。您可以在每个项目中定义一个 checkstyle 任务(它需要在每个项目中都有一个 xml 文件)。否则,您可以从 (github.com/android/platform_development/tree/master/ide/…) 导入 AS 的 AOSP 代码样式,让 IDE 为您完成工作。
  • @BenManes 评论中的链接已损坏
  • @EdmundJohnson 太糟糕了,所以不会将链接重写为特定于哈希。这是一个更正的link

标签: android gradle android-gradle-plugin checkstyle


【解决方案1】:

您应该始终指定要使用的 Checkstyle 的确切版本。 Checkstyle 的家伙经常做出破坏性的更改,除非您设置特定的固定版本,否则会使您的构建失败。例如:

checkstyle {
    configFile file('downloaded_google_checks.xml')
    toolVersion '6.9'    // set Checkstyle version here
    showViolations = true
}

然后,您还可以为您的版本使用正确的配置文件,例如:https://github.com/checkstyle/checkstyle/blob/checkstyle-6.9/src/main/resources/google_checks.xml。请注意 URL 中的版本号 - 这可以调整为您在 Gradle 配置中选择的版本。

不要使用来自 master 分支的最新配置文件,因为这与 master 分支上的当前代码(尚未发布)匹配。

以上允许您根据需要调整配置。如果您确定要原始规则文件,也可以按照@BenMane 的评论建议,直接引用捆绑的 google_checks.xml。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 2018-09-11
    • 2021-02-14
    • 2011-04-09
    • 1970-01-01
    相关资源
    最近更新 更多