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 sonar-maven-plugin itself uses ${project.build.sourceDirectory}
to do it right in every module.
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.
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.
Or should I ensure src/main
exists before sonar start? What hook may I use for that?
One of the things you can do it:
sonar.sources
to be .
sonar.inclusions
to be src/main/**
src/main
folder if it existssonar.exclusions
or sonar.inclusions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With