【问题标题】:How to override configLocation in maven checkstyle plugin?如何在 Maven checkstyle 插件中覆盖 configLocation?
【发布时间】:2014-11-27 05:46:44
【问题描述】:

我想覆盖 maven checkstyle 插件中的 configLocation 选项。 POM.xml 的示例部分是:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <configLocation>blahblah/checkstyle/checkstyle.xml</configLocation>
      <consoleOutput>true</consoleOutput>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>com.example.blahblah</groupId>
        <artifactId>checkstyle-config</artifactId>
        <version>2.0.0-SNAPSHOT</version>
      </dependency>
    </dependencies>
    <configuration>
      <configLocation>checkstyle.config.xml</configLocation>
      <suppressionsLocation>checkstyle.suppressions.xml</suppressionsLocation>

      ... other configuration ...

    </configuration>
  </plugin>

从上面可以看出,checkstyle-config 是一个单独的 maven 项目,其中包含样式检查的规则,用于规则的配置文件是 blahblah/checkstyle/checkstyle.xml。如果我必须覆盖 blahblah/checkstyle/checkstyle.xml 并使用存储在当前项目而不是 checkstyle-config 项目中的其他一些 .xml,那么我该怎么做?

【问题讨论】:

    标签: java maven checkstyle


    【解决方案1】:

    您可以通过复制上述插件配置部分并覆盖配置位置来覆盖模块中的插件配置。在此您可以将配置标签移动到执行中,以便该配置仅适用于该执行。 见下例

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>check</goal>
        </goals>
       <configuration>
          <configLocation>blahblah/checkstyle/checkstyle.xml</configLocation>
       </configuration>
      </execution>
    </executions>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 2011-04-28
      • 2011-05-30
      • 1970-01-01
      • 2013-12-28
      • 2011-09-18
      • 2016-04-29
      相关资源
      最近更新 更多