How can I configure checkstyle in maven?

℡╲_俬逩灬. 提交于 2019-12-05 17:48:52
Blundell

For it to pick up your custom configuration, you need to declare your file as a property:

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...

  <properties>
    <checkstyle.config.location><!-- file location --></checkstyle.config.location>
  </properties>

  <build>
    ...

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.9.1</version>
      </plugin>
    </plugins>
  </build>

</project>

Taken from my tutorial on how to create a custom CheckStyle check here:
http://blog.blundellapps.com/create-your-own-checkstyle-check/

Source code here:
https://github.com/blundell/CreateYourOwnCheckStyleCheck

yodamad

Why you don't put your checkstyle config in a directory in parent project like src/main/resources and parametrized the plugin in parent pom.xml like this

<!-- Checkstyle -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>RELEASE</version>
    <configuration>
        <configLocation>src/main/resources/checkstyle.xml</configLocation>                   
    </configuration>
</plugin>

Child projects should have access do this configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!