Checkstyle gradle在检查样式时无法实例化AvoidConstantAsFirstOperandInConditionCheck

时间:2015-07-17 09:57:12

标签: gradle checkstyle sevntu-checkstyle

我已经配置了我的Gradle构建脚本以使用checkstyle和添加的sventu checkstyle检查,但是当我执行checkstyleMain任务时,构建失败并出现以下错误:

* What went wrong:
Execution failed for task ':checkstyleMain'.
> Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate AvoidConstantAsFirstOperandInConditionCheck

即使我在我的构建中包含了checkstyle jar,也会发生这种情况。以下是我的构建脚本的相关部分:

repositories {
      mavenCentral()
      maven {
          url "http://sevntu-checkstyle.github.com/sevntu.checkstyle/maven2"
      }
   }

checkstyle {
    configFile = new File("etc/config/dev.xml");
    toolVersion = "6.8"
}

configurations {
    checkstyle
}

dependencies {  
    checkstyle "com.github.sevntu.checkstyle:sevntu-checks:1.13.4"
}

请注意,当我删除依赖项部分并使用未配置额外sevntu检查的checkstyle xml doc进行测试时,构建工作正常。我的配置也类似于sevntu-checkstyle/checkstyle-samples

的示例

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

所以我终于明白了:

如果您将自定义检查的完整类路径作为每个自定义检查的名称,则https://github.com/sevntu-checkstyle/checkstyle-samples/blob/master/gradle-project/build.gradle处的示例才有效。

这是由于checkstyle不知道自定义检查在包中的位置。如果在jar中包含一个描述包含检查的包的checkstyle_packages.xml文件,checkstyle可以找到它。

不幸的是,com.github.sevntu.checkstyle中没有这样的文件:sevntu-checks:1.13.4。要获取此信息,还需要包含“com.github.sevntu.checkstyle:sevntu-checkstyle-maven-plugin:1.13.4”,它基本上只包含checkstyle_packages.xml文件。

所以我已将此添加到我的依赖项中,checkstyle规则最终解析:

dependencies {
    checkstyle "com.github.sevntu.checkstyle:sevntu-checks:1.13.4",
               "com.github.sevntu.checkstyle:sevntu-checkstyle-maven-plugin:1.13.4"
}

希望这能为将来的某些人带来一些痛苦:)

相关问题