【问题标题】:How to find which checkstyle version gradle is using?如何找到 gradle 正在使用的 checkstyle 版本?
【发布时间】:2018-05-22 18:07:33
【问题描述】:

在我的 gradle 文件中,我有:

apply plugin: 'checkstyle'

我正在尝试创建自己的检查样式规则。出于这个原因,我在我的 gradle 文件中添加了一个依赖项。

dependencies {
     checkstyle 'com.puppycrawl.tools:checkstyle:8.2'
}

我正在尝试扩展 checkstyle 的“Check”类。但是checkstyle的版本很多,不知道gradle用的是哪一个。

如何找到 gradle 使用的 checkstyle 的确切版本号?

【问题讨论】:

    标签: android gradle checkstyle


    【解决方案1】:

    目前我能想到三种方式,首先最不吸引人:

    • 您可以查看 Gradle source code
    • 您可以查看Checkstyle Compatibility Matrix(L 列,黄色单元格)。
      两者都说从 Gradle 3.3 开始,默认的 Checkstyle 版本是 6.19;之前是5.9。只有 2.4 之前的 Gradle 版本使用了更旧版本的 Checkstyle。
    • 但是推荐的方法是选择 Checkstyle 版本,通过在 build.gradle 文件中指定它:

      checkstyle {
          configFile file('your/checkstyle.xml');
          toolVersion '8.2';    // your choice here
      }
      

      这比依赖默认版本要好,因为您可以使用更新版本的 Checkstyle,并且在更新 Gradle 时您的 Checkstyle 设置不会中断。

    【讨论】:

    • 您如何确保在您的项目中专门使用了哪一个?
    【解决方案2】:

    提供更好的解决方案,可以参考checkstyle源码中的配置文件示例,不用担心兼容性问题。

    只需运行gradle dependencies | grep checkstyle

    然后在此处获取相应的checkstyle源以参考配置示例:https://github.com/checkstyle/checkstyle/releases

    【讨论】:

    • 为什么投反对票?这不需要刷新依赖项。
    【解决方案3】:

    您可以通过将其写入您的 build.gradle 文件并重新加载您的 gradle 项目来检查 checkstyle.toolVersion 的当前值

    plugins {
        id 'java'
        id 'checkstyle'
    }
    
    println checkstyle.toolVersion
    

    【讨论】:

      【解决方案4】:

      使用开箱即用的apply plugin: 'checkstyle',检查样式​​将使用v6.19

      下载的依赖:

      Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.19/checkstyle-6.19.pom
      Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.5.3/antlr4-runtime-4.5.3.pom
      Download https://repo1.maven.org/maven2/org/antlr/antlr4-master/4.5.3/antlr4-master-4.5.3.pom
      Download https://repo1.maven.org/maven2/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.pom
      Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.pom
      Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/41/commons-parent-41.pom
      Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar
      Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.19/checkstyle-6.19.jar
      Download https://repo1.maven.org/maven2/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar
      Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.5.3/antlr4-runtime-4.5.3.jar
      

      dependencies { checkstyle 'com.puppycrawl.tools:checkstyle:8.2' }之后,下载的依赖列表:

      Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/8.2/checkstyle-8.2.pom
      Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.7/antlr4-runtime-4.7.pom
      Download https://repo1.maven.org/maven2/org/antlr/antlr4-master/4.7/antlr4-master-4.7.pom
      Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.4/commons-cli-1.4.pom
      Download https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-4/Saxon-HE-9.8.0-4.pom
      Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.7/antlr4-runtime-4.7.jar
      Download https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-4/Saxon-HE-9.8.0-4.jar
      Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.4/commons-cli-1.4.jar
      Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/8.2/checkstyle-8.2.jar
      

      【讨论】:

        猜你喜欢
        • 2014-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-13
        • 2021-12-26
        • 1970-01-01
        • 2018-12-08
        • 2016-09-23
        相关资源
        最近更新 更多