Hi,
I use Community Edition Version 9.6.1 (build 59531).
This question was asked already on Stackoverflow a while ago (java - sonar-maven-plugin: extending sonar.sources in multi-module project - Stack Overflow), got a helpful answer but now is facing deprecation warnings:
The original question
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.
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
:
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.
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:\...\submodule\src\main\resources' does not exist for Maven module ... Please check the property sonar.sources -> [Help 1]
The original answer
One of the things you can do it:
- 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 - In your modules, if you want to control better what gets in, you just have to use/override sonar.exclusions or sonar.inclusions
The deprecation warnings
Now I’m facing the deprecation warnings
[WARNING] Specifying module-relative paths at project level in the property 'sonar.inclusions' is deprecated. To continue matching files like 'my-submodule1/src/main/java/com/foo/Foo.java', update this property so that patterns refer to project-relative paths
My question
Do I really have to list all paths my-submodule1/src/main,my-submodule2/src/main,...,my-submodule100/src/main
in sonar.sources
separately in favor of sonar.inclusions
? This is error-prone, if there are modules added and one will forget to add it to sonar.sources
.