【发布时间】:2016-09-29 09:21:39
【问题描述】:
我想将sonar.sources(默认为pom.xml,src/main/java)扩展为src/main/resources,以便检查位于那里的XML 文件。
这个看似简单的任务结果却很困难,因为我有一个多模块 maven 项目(> 100 个模块,嵌套)其中很多没有src/main/resources 文件夹,其中大多数甚至没有@ 987654326@ 文件夹(例如用于包装=pom)。如果我将sonar.sources 设置为pom.xml,src/main/java,src/main/resources 或pom.xml,src/main,这会导致构建错误:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) on project xyz-parent: The directory 'C:\...\submodule\src\main\resources' does not exist for Maven module ... Please check the property sonar.sources -> [Help 1]
sonar-maven-plugin 本身使用 ${project.build.sourceDirectory} 在每个模块中正确执行此操作。
我尝试使用正则表达式将sonar.sources 设置为src/main,方法是通过切断/java(或Windows 上的\java)
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>sonar.sources</name>
<value>${project.build.sourceDirectory}</value>
<regex>[/\\]+java$</regex>
<replacement></replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
但这没有任何作用,我不知道我应该将它绑定到哪个生命周期阶段以使其执行。
或者有没有办法避免由于sonar.sources 中缺少目录而导致的错误?根据current sonar-maven source,只有在POM 有pom 打包但ear 或jar 没有资源的模块时才会忽略缺少的目录。
或者我应该确保src/main 在声纳启动之前存在?我可以使用什么钩子?
【问题讨论】: