java - 运行 mvn checkstyle :checkstyle 时出错

标签 java maven plugins eclipse-plugin checkstyle

执行命令mvn checkstyle:checkstyle时出现以下错误:

An error has occurred in Checkstyle report generation.
...
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Unable to instantiate GenericIllegalRegexp
    at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:178)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:184)
    at org.apache.maven.plugin.checkstyle.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:170)
    at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:259)
    ... 24 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate GenericIllegalRegexp
    at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:155)
    at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:184)
    at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:157)
... 27 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate GenericIllegalRegexpCheck
    at com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:98)
    at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:152)
    ... 30 more

我猜这个错误与使用旧版本的 checkstyle 创建的规则有关。

pom.xml 中的 checkstyle 插件配置为:

...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
    <configLocation>checkstyle.xml</configLocation>
    <headerLocation>LICENSE.txt</headerLocation>
</configuration>
</plugin>
...

是否有方法或工具可以迁移规则以使其与 checkstyle 5.5 兼容? (除了根据 checkstyle 文档概述每个规则的规则)

最佳答案

我已经设法通过修改规则的 xml 来消除该特定异常。
我已经替换:

<module name="GenericIllegalRegexp">
  <property name="format" value="\s+$"/>
  <property name="message" value="Line has trailing spaces."/>
  <property name="ignoreComments" value="true"/>
</module>

<module name="RegexpSinglelineJava">
  <property name="format" value="\s+$"/>
  <property name="message" value="Line has trailing spaces."/>
  <property name="ignoreComments" value="true"/>
</module>

希望我能帮助遇到同样问题的人。问候。

关于java - 运行 mvn checkstyle :checkstyle 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12433466/

相关文章:

ruby-on-rails - 我是否应该将二进制文件包含在 Rails 插件中?

java - J2ME 中的认证错误

java - 无法在某些构建类型上运行自动化 Android 测试? JUnit 和 UiAutomator 导入无法解析

java - Windows 7 上的 apache ant 安装

java - 连接到 MySQL DB : better an . ini 文件或 .bat 文件?

java - Spring xml + JUnit - xml 上下文文件在 src/test/resources 中不起作用但在 src/main/resources 中起作用

java - Spring Boot升级后"NoSuchMethodError getHttpServletMapping"

java插件缓存和动态IP主机

java - Spring Security NoClassDefFoundError

jquery - <plugin> 不是一个函数