【发布时间】:2018-03-04 13:55:59
【问题描述】:
我在我的基本目录中创建了一个简单的初始 my-checks.xml 文件,它可以被 intelliJ 验证和使用:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
<module name="Checker">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
http://checkstyle.sourceforge.net/5.x/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->
<property name="fileExtensions" value="java, properties, xml"/>
<module name="TreeWalker">
<module name="NeedBraces"/>
</module>
</module>
在基本目录中的 pom.xml 中,我有以下内容:
<build>
..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>my-checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
..
</build>
现在我可以运行mvn clean install 并在target 文件夹中生成checkstyle-checker.xml。此文件将与my-checks.xml 相同。伟大的!到目前为止一切顺利!
现在我运行mvn checkstyle:check...
看来checkstyle-checker.xml跑目标的时候被sun-checks.xml换掉了!!!
如何使用自己的配置???
【问题讨论】:
-
顺便说一下,Intellij 将 linkXRef 标记标记为红色并说“此处不允许”我认为这只是 intellj 的问题,但不确定所以我要提到它。跨度>
-
显然我可以做到: mvn checkstyle:check -Dcheckstyle.config.location=[path to my checkstyle file] 但这是迟钝的!我希望 pom 中的配置就足够了
标签: maven checkstyle maven-checkstyle-plugin