2017-02-07 14 views
0

我試圖將checkstyle插件與名爲checkstyle.xml的自定義checkstyle文件一起使用。 I have followed the guide。這是我的POM:Maven checkstyle插件。 CheckstyleException:模塊Para​​meterName中的屬性'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.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> 

所以,我不知道我在做什麼錯。

+0

'的CheckStyle這裏提到指定的插件的CheckStyle定義 最新版本。 xml'是指南的建議。 – nullpointer

+0

在最近版本的checkstyle插件中引入了accessModifiers,以取代範圍。如果你移除了accessModifiers元素,它會起作用嗎?也可以嘗試在你的(根據以下6.11.2)配置中使用最新的插件,如下所示:https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html – Santo

+0

@nullpointer文件只是處於不同的位置。 – giuseta

回答

0

accessModifiers僅在checkstyle版本7.5中引入。請參閱下面的發行說明。 http://checkstyle.sourceforge.net/releasenotes.html

  1. 可以使模塊定義由 與舊版本兼容去除accessModifiers和添加範圍來代替。
  2. 您可以(通過defualt其6.11.2)

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

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

+0

我已經試過了7.5版本,但它仍然不起作用。 – giuseta

+0

@giuseta你如何將它改爲7.5?你是否聲明pluginmanagment覆蓋依賴?我能夠得到它的工作 – Santo

+0

也看看我問的問題,http://stackoverflow.com/questions/42121531/dependencies-added-in-pluginmanagement-not-considered-during-reporting/42122294#42122294 – Santo

相關問題