5

我有一个项目,它由几个 Maven 模块组成,这些模块都是父模块的子模块。我将父级设置为使用 checkstyle 并且子模块都正确继承了此行为。我希望所有子模块都使用其插件中定义的父抑制文件。我定义了一个在 checkstyle 插件中使用的属性checkstyle.suppression

<properties>
  <checkstyle.suppressions>${basedir}\src\checkstyle\suppressions.xml</checkstyle.suppressions>
</properties>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.2</version>
    <configuration>
      <configLocation>config/sun_checks.xml</configLocation>
      <suppressionsLocation>${checkstyle.suppressions}</suppressionsLocation>
      <suppressionsFileExpression>${checkstyle.suppressions}</suppressionsFileExpression>
    </configuration>
  </plugin>
</plugins>

这对父级工作正常,但所有子模块都试图在它们的basedir中找到文件,这确实有意义。
我确信必须有一个我缺少的简单解决方案,但是有没有办法定义这个位置,以便所有子模块都将使用父位置而不用硬编码它?

4

4 回答 4

11

The answers above are dangerous. I maintain that each project should be self contained, so referring to files external to it is going to break a build sooner or later. Checkstyle can take a url for the file but that means you can't build offline. A better approach is to package your file (can also add pmd.xml) into a jar and then add that jar to the classpath of the checkstyle (or pmd) plugin. I have an example of it here and more about overridding a plugin classpath here

于 2009-09-03T18:24:01.307 回答
2

该插件的文档在这里提到了一个类似的用例: http ://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html

于 2009-09-03T17:21:56.240 回答
0

您是否尝试过在父 pom 中定义这样的属性或在孩子中重新定义它?

 <properties>
   <checkstyle.suppressions>${parent.project.basedir}\src\checkstyle\suppressions.xml</checkstyle.suppressions>
 </properties>
于 2009-09-03T15:29:33.813 回答
0

如果父级不打算运行 checkstyle,您也许可以将其重写为

<properties>
  <checkstyle.suppressions>..\..\src\checkstyle\suppressions.xml</checkstyle.suppressions>
</properties>

或者类似的东西。或者,您可以在 settings.xml 中添加一些内容以将所有内容指向系统范围的配置目录。

虽然可能不建议这样做,但您可以使用引导程序或设置项目或任务将 suppresss.xml 文件的副本放置到由 settings.xml 中的属性指定的位置,然后始终通过该位置引用它地点。

于 2009-09-03T15:34:39.470 回答