我已经实现了一个 Checkstyle 监听器。它以前工作过,(我认为是 5.0 beta 版本),但现在(使用 5.0),checkstyle 失败并出现以下 CallStack
Unable to create Checker: cannot initialize module de.xyz.toxicity.TeamcityListener - Unable to instantiate de.xyz.toxicity.TeamcityListener
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module de.xyz.toxicity.TeamcityListener - Unable to instantiate de.xyz.toxicity.TeamcityListener
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:177)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:207)
at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:138)
at com.puppycrawl.tools.checkstyle.Main.main(Main.java:115)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate de.xyz.toxicity.TeamcityListener
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:156)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:152)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate de.xyz.toxicity.TeamcityListenerCheck
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:99)
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:153)
... 4 more
我的配置文件看起来像这样
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="de.xyz.toxicity.TeamcityListener" />
<module name="FileLength">
<property name="max" value="500"/>
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
<module name="AnonInnerLength">
<property name="max" value="35"/>
</module>
// ... more modules like this follow
</module>
</module>
从配置中删除我自己的侦听器后,一切正常。
真正让我困惑的是:为什么 checkstyle 会寻找 TeamcityListenerCheck 类?这样的类是不存在的。我需要吗?它应该是什么样子?