Maven checkstyle插件。 CheckstyleException:Property' accessModifiers'模块Para​​meterName中不存在

时间:2017-02-07 16:36:43

标签: java maven checkstyle

我尝试将checkstyle插件与名为checkstyle.xml的自定义checkstyle文件一起使用。 I have followed the guide。这是我的POM:

...
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <configLocation>src/main/resources/checkstyle.xml</configLocation>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>checkstyle</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>
...

checksyle.xmlthe google checkstyle file(我只重命名了该文件)。问题是,当我运行mvn -X site时,我得到以下错误:

Caused by: org.apache.maven.reporting.MavenReportException: Failed during checkstyle configuration
at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:488)
at org.apache.maven.plugin.checkstyle.CheckstyleReport.executeReport(CheckstyleReport.java:154)
at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)
at org.apache.maven.plugins.site.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:219)
... 26 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Property 'accessModifiers' in module ParameterName does not exist, please check the documentation
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:168)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:137)
at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:218)
at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)
... 29 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Property 'accessModifiers' in module ParameterName does not exist, please check the documentation
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:164)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:130)
at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:177)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:137)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:163)
... 32 more

我检查了checkstyle文件,并定义了accessModifiers属性。

....
<module name="ParameterName">
    <property name="id" value="ParameterNameNonPublic"/>
    <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
    <property name="accessModifiers" value="protected, package, private"/>
    <message key="name.invalidPattern" value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
    <property name="id" value="ParameterNamePublic"/>
    <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
    <property name="accessModifiers" value="public"/>
    <message key="name.invalidPattern" value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>

所以,我不知道自己做错了什么。

1 个答案:

答案 0 :(得分:0)

accessModifiers 仅在checkstyle 7.5版中引入。请参阅下面的发行说明。 http://checkstyle.sourceforge.net/releasenotes.html

  1. 您可以通过以下方式使模块定义与旧版本兼容 删除accessModifiers并添加范围。
  2. 您可以在checkstyle插件中指定最新版本 这里提到的定义(通过defualt其6.11.2)
  3. https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading- checkstyle.html

    https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html

相关问题