我尝试将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.xml
是the 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>
所以,我不知道自己做错了什么。
答案 0 :(得分:0)
accessModifiers 仅在checkstyle 7.5版中引入。请参阅下面的发行说明。 http://checkstyle.sourceforge.net/releasenotes.html
https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading- checkstyle.html
https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html