如何修复maven checkstyle插件错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.2:check (validate) on project yourproject:
Failed during checkstyle execution:
Failed during checkstyle configuration: unable to parse configuration stream:
com.puppycrawl.tools.checkstyle.api.CheckstyleException:
Property ${samedir} has not been set -> [Help 1]
${samedir}是一个与eclipse插件很好地工作的属性,并且需要在checkstyle配置中得到与eclipse IDE很好地工作的相关文件。所以要么我需要一个一致的替换,要么我可以告诉maven定义属性
有什么办法解决这个问题吗?
您必须通过您的pom中的插件配置来设置这些值。
如果在项目根目录中有一个名为checks
的目录,则pom.xml
的示例配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<configLocation>${basedir}/checks/checkstyle.xml</configLocation>
<propertiesLocation>${basedir}/checks/checkstyle_maven.properties</propertiesLocation>
</configuration>
</plugin>
和checkstyle_maven.properties
含量:
samedir=checks
作为<propertiesLocation>
的替代方案,您还可以使用以下内容,在这种情况下,您不需要.properties
文件:
<propertyExpansion>samedir=${basedir}/checks</propertyExpansion>
这将确保checkstyle.xml
中的任何配置都像这样工作:
<module name="Checker">
<module name="SuppressionFilter">
<property name="file" value="${samedir}/suppress.xml"/>
</module>
</module>
参考:
- 在Gradle和Eclipse的checkstyle插件中使用${samedir}
- http://rolf-engelhard.de/2011/04/using-the-same-suppression-filter-for-checkstyle-in-eclipse-and-maven/