问题描述
我尝试使用Google checkstyle配置(),但我经常在 gradle check
:
无法创建检查器:无法初始化模块TreeWalker - 无法实例化EmptyCatchBlock
我使用Gradle构建项目。以下是我的gradle.build。
apply plugin:'java'
apply plugin:'idea'
apply plugin:'checkstyle'
sourceCompatibility = 1.8
version ='1.0'
checkstyle {
toolVersion =6.3
}
任务create-dirs<< {
sourceSets * .java.srcDirs * .each {it.mkdirs()}
sourceSets * .resources.srcDirs * .each {it.mkdirs()}
}
jar {
manifest {
attributes'Implementation-Title':'xyz',
'Implementation-Version':0.01
}
}
repositories {
mavenCentral()
}
依赖项{
compile(
['org.apache.logging.log4j: log4j-api:2.2'],
['org.apache.logging.log4j:log4j-core:2.2']
)
testCompile(
['junit:junit: 4.11'],
['org.mockito:mockito-core:1. +']
)
}
test {
systemProperties'property ':'value'
}
uploadArchives {
repositories {
flatDir {
dirs'repos'
}
}
}
另外,当我尝试将XML配置文件添加到IDEA I中的Checkstyle插件相似错误但带有堆栈跟踪:
org.infernus.idea.checkstyle.exception.CheckStylePluginException:< html>< b> ;无法加载CheckStyle规则文件< / b>< br>无法初始化模块TreeWalker - 无法实例化EmptyCatchBlock< / html>
at org.infernus.idea.checkstyle.checker.CheckerFactory.blacklistAndShowMessage(CheckerFactory.java:234)
at org.infernus.idea.checkstyle.checker.CheckerFactory.createChecker(CheckerFactory.java:188)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getOrCreateCachedChecker(CheckerFactory.java:98)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:73)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:41)
我无法弄清楚我做错了什么。任何帮助,将不胜感激。
Gradle版本:2.2
问题在于 com.puppycrawl。 tools.checkstyle.checks.blocks.EmptyCatchBlockCheck
确实已添加到checkstyle,但用于版本6.4-SNAPSHOT。正如在checkstyle 。 Checkstyle jar是用 mvn clean package
构建的,源代码来自回购。
I am trying to use Google checkstyle configuration (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml) but I am constantly getting an error on gradle check
:
Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
I used Gradle to build the project. Below is my gradle.build.
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'checkstyle'
sourceCompatibility = 1.8
version = '1.0'
checkstyle {
toolVersion = "6.3"
}
task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
jar {
manifest {
attributes 'Implementation-Title': 'xyz',
'Implementation-Version': 0.01
}
}
repositories {
mavenCentral()
}
dependencies {
compile (
['org.apache.logging.log4j:log4j-api:2.2'],
['org.apache.logging.log4j:log4j-core:2.2']
)
testCompile(
['junit:junit:4.11'],
['org.mockito:mockito-core:1.+']
)
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
Also, when I try to add XML config file to Checkstyle plugin in IDEA I get similar error but with a stack trace:
org.infernus.idea.checkstyle.exception.CheckStylePluginException: <html><b>The CheckStyle rules file could not be loaded.</b><br>cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock</html>
at org.infernus.idea.checkstyle.checker.CheckerFactory.blacklistAndShowMessage(CheckerFactory.java:234)
at org.infernus.idea.checkstyle.checker.CheckerFactory.createChecker(CheckerFactory.java:188)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getOrCreateCachedChecker(CheckerFactory.java:98)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:73)
at org.infernus.idea.checkstyle.checker.CheckerFactory.getChecker(CheckerFactory.java:41)
I cannot figure out what am I doing wrong. Any help would be appreciated.Gradle version: 2.2
The problem lies in the fact that com.puppycrawl.tools.checkstyle.checks.blocks.EmptyCatchBlockCheck
was indeed added to checkstyle but for version 6.4-SNAPSHOT. As it can be seen in checkstyle repository (pom.xml history) version 6.4-SNAPSHOT was introduced on the 02.02.2015 and EmptyCatchBlockCheck
class was created on 18.02.2015.
Gradle still uses version 6.3 as in the following log extract:
:checkstyleMain
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.3/checkstyle-6.3.pom
So there's simply no class You'd like to use.
According to the docs checkstyle classpath can be specified with checkstyleClasspath
property - you can try to set it up manually.
I've also prepared a demo with 6.4-SNAPSHOT version, it can be found here. Checkstyle jar was built with mvn clean package
with source taken from this repo.
这篇关于如何使用Gradle编译Google Checkstyle规则的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!