sonar-maven-plugin: extending sonar.sources in multi-module project(sonar-maven-plugin:在多模块项目中扩展 sonar.sources)
问题描述
我想扩展 sonar.sources
,默认情况下是 pom.xml,src/main/java
,由 src/main/resources
code> 以检查位于那里的 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:...submodulesrcmain
esources' 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 besrc/main/**
- => this will include all the known files that SQ finds in your modules in the
src/main
folder if it exists
这篇关于sonar-maven-plugin:在多模块项目中扩展 sonar.sources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sonar-maven-plugin:在多模块项目中扩展 sonar.sources
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01