我試圖將checkstyle插件與名爲checkstyle.xml
的自定義checkstyle文件一起使用。 I have followed the guide。這是我的POM:Maven checkstyle插件。 CheckstyleException:模塊ParameterName中的屬性'accessModifiers'不存在
...
<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>
所以,我不知道我在做什麼錯。
'的CheckStyle這裏提到指定的插件的CheckStyle定義 最新版本。 xml configLocation>'是指南的建議。 –
nullpointer
在最近版本的checkstyle插件中引入了accessModifiers,以取代範圍。如果你移除了accessModifiers元素,它會起作用嗎?也可以嘗試在你的(根據以下6.11.2)配置中使用最新的插件,如下所示:https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html – Santo
@nullpointer文件只是處於不同的位置。 – giuseta