Kay*_*ser 4 java configuration checkstyle maven
我正在使用Maven
我有一个父模块和一些其他模块.他们看着像是:
PARENT
??? pom.xml
??? ModulA
| ??? pom.xml
??? ModulB
??? pom.xml
??? folder
??? checkstyle.xml
我试图用自己的规则替换规则.但它忽略了我的规则.我将插件添加到父pom.xml中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<configLocation>
${basedir}/../ModulB/folder/checkstyle.xml
</configLocation>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题出在哪儿?
编辑:
mvn checkstyle:checkstyle -X
...
<configuration>
<cacheFile default-value="${project.build.directory}/checkstyle-cachefile"/>
<configLocation default-value="config/sun_checks.xml">${checkstyle.config.location}</configLocation>
<consoleOutput default-value="false"/>
<enableFilesSummary default-value="true">${checkstyle.enable.files.summary}</enableFilesSummary>
<enableRSS default-value="true">${checkstyle.enable.rss}</enableRSS>
<enableRulesSummary default-value="true">${checkstyle.enable.rules.summary}</enableRulesSummary>
<enableSeveritySummary default-value="true">${checkstyle.enable.severity.summary}</enableSeveritySummary>
<encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding>
<excludes>${checkstyle.excludes}</excludes>
<failsOnError default-value="false"/>
<format default-value="sun"/>
<headerFile>${basedir}/LICENSE.txt</headerFile>
<headerLocation default-value="LICENSE.txt">${checkstyle.header.file}</headerLocation>
<includeTestSourceDirectory default-value="${false}"/>
<includes default-value="**/*.java">${checkstyle.includes}</includes>
<linkXRef default-value="true">${linkXRef}</linkXRef>
<outputDirectory default-value="${project.reporting.outputDirectory}"/>
<outputFile default-value="${project.build.directory}/checkstyle-result.xml">${checkstyle.output.file}</outputFile>
<outputFileFormat default-value="xml">${checkstyle.output.format}</outputFileFormat>
<project default-value="${project}"/>
<propertiesLocation>${checkstyle.properties.location}</propertiesLocation>
<skip default-value="false">${checkstyle.skip}</skip>
<sourceDirectory default-value="${project.build.sourceDirectory}"/>
<suppressionsFileExpression default-value="checkstyle.suppressions.file">${checkstyle.suppression.expression}</suppressionsFileExpression>
<suppressionsLocation>${checkstyle.suppressions.location}</suppressionsLocation>
<testSourceDirectory default-value="${project.build.testSourceDirectory}"/>
<xrefLocation default-value="${project.reporting.outputDirectory}/xref"/>
</configuration>
...
Run Code Online (Sandbox Code Playgroud)
Blu*_*ell 12
要获取自定义配置,您需要将文件声明为属性:
<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>
Run Code Online (Sandbox Code Playgroud)
从我的教程中获取如何创建自定义CheckStyle检查:http:
//blog.blundellapps.com/create-your-own-checkstyle-check/
源代码在这里:https:
//github.com/blundell/CreateYourOwnCheckStyleCheck
为什么你不将 checkstyle 配置放在父项目的目录中,并像src/main/resources这样在父 pom.xml 中参数化插件
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
子项目应该有权执行此配置
| 归档时间: |
|
| 查看次数: |
20168 次 |
| 最近记录: |