问题描述
我想扩展 sonar.sources,默认情况下是 pom.xml,src/main/java,由 src/main/resourcescode> 以检查位于那里的 XML 文件.
I want to extend sonar.sources, which by default is pom.xml,src/main/java, by src/main/resources in order to check XML files that are located there.
这个看似简单的任务结果却很困难,因为我有一个多模块 maven 项目(> 100 个模块,嵌套)其中很多没有 src/main/resources文件夹,其中大多数甚至不是 src 文件夹(例如,用于 Packaging=pom).如果我将 sonar.sources 设置为 pom.xml,src/main/java,src/main/resources 或 pom.xml,这会导致构建错误,src/main:
This seemingly simple task turned out to be difficult since I have a multi-module maven project (> 100 modules, nested) with a lot of them don't have a src/main/resources folder and most of them not even a src folder (e.g. for packaging=pom). This leads to a build error if I set sonar.sources to pom.xml,src/main/java,src/main/resources or 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:...submodulesrcmainesources' does not exist for Maven module ... Please check the property sonar.sources -> [Help 1]
sonar-maven-plugin 本身使用 ${project.build.sourceDirectory} 在每个模块中正确执行此操作.
The sonar-maven-plugin itself uses ${project.build.sourceDirectory} to do it right in every module.
我尝试使用正则表达式通过切断 /java(或 java 在 Windows 上)通过
I tried to use regular expressions to set sonar.sources to src/main by cutting off /java (or java on Windows) via
<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>
但这没有任何作用,我不知道我应该将它绑定到哪个生命周期阶段以使其执行.
But this does nothing and I have no idea to which lifecycle phase I should bind it to have it executed.
或者有没有办法避免由于 sonar.sources 中缺少目录而导致的错误?根据 当前 sonar-maven 源 缺少的目录仅在 POM 具有 pom 包装但不适用于 ear 或 jar 时被忽略没有资源的模块.
Or is there a way to avoid the error due to missing directory in sonar.sources? According to current sonar-maven source missing directories are only ignored if the POM has pom packaging but not for ear or jar modules without resources.
或者我应该确保 src/main 在声纳启动之前存在?我可以使用什么钩子?
Or should I ensure src/main exists before sonar start? What hook may I use for that?
推荐答案
你能做到的事情之一:
- 在您的根 POM 中,定义以下属性:
- sonar.sources 为 .
- sonar.inclusions 为 src/main/**
- => 这将包括 SQ 在 src/main 文件夹中的模块中找到的所有已知文件(如果存在)
- In your root POM, define the following properties:
- sonar.sources to be .
- sonar.inclusions to be src/main/**
- => this will include all the known files that SQ finds in your modules in the src/main folder if it exists