Checkstyle 插件不关心外部配置文件中的内容
Checkstyle plugin doesn't care what's in external configuration file
我正在尝试将 Maven Checkstyle 插件与外部配置文件一起使用。该插件可以在指定或不指定外部配置文件的情况下工作,并且检查系统警告会有所不同,具体取决于是否设置了 configLocation。所以看起来它应该工作正常,但事实并非如此。无论我在外部配置文件中输入什么,似乎都会生成相同的警告。事实上,我可以完全清除文件并且似乎没有任何变化。
在 pom 中:
<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>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
正在尝试使用此文件:
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
在 pom 中,如果我将名称更改为 "does_not_exist.xml",它将报告找不到带有以下消息的文件:
Unable to find configuration file at location: does_not_exist.xml
由于它没有使用正确的文件名打印此消息,它告诉我它可以找到具有正确名称的文件 (google_checks.xml)。
在文件中:
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
如果我将值更改为 10,我仍然会收到警告:
Line is longer than 100 characters...
我是 运行:
mvn clean verify
我试过将 google_checks.xml 文件放在项目的根目录和 src/main/resources
目录中。两个位置的结果相同。
我最终想更改行长和缩进的规则,但由于它不关心我在文件中输入的内容,我不确定如何执行此操作。关于如何让它尊重外部文件中的内容的任何想法?
相当挖苦但是:
configLocation
你在你的问题中设置了 XML 被注入到 maven-checkstyle-plugin 的 CheckstyleViolationCheckMojo#configLocation 中,因为这个变量是私有的,所以它没有出现在他们的 Javadoc 上,但是它记录在源代码中。
此描述指出:
This parameter is resolved as resource, URL, then file. If
successfully resolved, the contents of the configuration is copied into
the ${project.build.directory}/checkstyle-configuration.xml file before
being passed to Checkstyle as a configuration.
There are 2 predefined rulesets.
- sun_checks.xml: Sun Checks.
- google_checks.xml: Google Checks.
我认为发生的事情是它没有以正常方式解析参数,因为google_checks.xml
是一个预定义的规则集,因此默认 google_checks.xml
将被加载。
如果您想使用自己的自定义配置器,您应该将其命名为 google_checks.xml
和 sun_checks.xml
以外的名称
我正在尝试将 Maven Checkstyle 插件与外部配置文件一起使用。该插件可以在指定或不指定外部配置文件的情况下工作,并且检查系统警告会有所不同,具体取决于是否设置了 configLocation。所以看起来它应该工作正常,但事实并非如此。无论我在外部配置文件中输入什么,似乎都会生成相同的警告。事实上,我可以完全清除文件并且似乎没有任何变化。
在 pom 中:
<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>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
正在尝试使用此文件:
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
在 pom 中,如果我将名称更改为 "does_not_exist.xml",它将报告找不到带有以下消息的文件:
Unable to find configuration file at location: does_not_exist.xml
由于它没有使用正确的文件名打印此消息,它告诉我它可以找到具有正确名称的文件 (google_checks.xml)。
在文件中:
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
如果我将值更改为 10,我仍然会收到警告:
Line is longer than 100 characters...
我是 运行:
mvn clean verify
我试过将 google_checks.xml 文件放在项目的根目录和 src/main/resources
目录中。两个位置的结果相同。
我最终想更改行长和缩进的规则,但由于它不关心我在文件中输入的内容,我不确定如何执行此操作。关于如何让它尊重外部文件中的内容的任何想法?
相当挖苦但是:
configLocation
你在你的问题中设置了 XML 被注入到 maven-checkstyle-plugin 的 CheckstyleViolationCheckMojo#configLocation 中,因为这个变量是私有的,所以它没有出现在他们的 Javadoc 上,但是它记录在源代码中。
此描述指出:
This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the configuration is copied into the ${project.build.directory}/checkstyle-configuration.xml file before being passed to Checkstyle as a configuration.
There are 2 predefined rulesets.
- sun_checks.xml: Sun Checks.
- google_checks.xml: Google Checks.
我认为发生的事情是它没有以正常方式解析参数,因为google_checks.xml
是一个预定义的规则集,因此默认 google_checks.xml
将被加载。
如果您想使用自己的自定义配置器,您应该将其命名为 google_checks.xml
和 sun_checks.xml