When I run the mvn sonar:sonar command, it only scans /module1 and /module2 but does not perform analysis on the files within /non-mvn-module-directory.
If I try to specify <sonar.sources>non-mvn-module-directory/</sonar.sources> in pom.xml or specify it within <sonar.inclusions> it reads this as an inclusion within each mvn module like:
Indexing files of module 'module1'
Included sources: non-mvn-module-directory
How can I perform a scan on this directory similar to how it’s run on each mvn module?
When you analyze with Maven it takes project context, including the locating of source files, from Maven’s Java-centric context. To add non-Java files, you’ll need to override sonar.souces with a complete list, so (on the command line) -Dsonar.sources=module1/subdir,module2/subdir,non-mvn-module-directory/subdir.
I did try running it with the suggested argument mvn sonar:sonar -Dsonar.sources=module1/subdir,module2/subdir,non-mvn-module-directory/subdir but I get the following error:
The directory '.../cache/module1/subdir' does not exist for Maven module <some-other-module>. Please check the property sonar.sources
I tried adding this some-other-module to the sonar.exclusions but still get this cache/ error. Any idea how can I overcome this?
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project <project>: The directory '/<dir>/<user>/<dir>/<projectRoot>/cache/module1/src' does not exist for Maven module com.<project>:cache:jar:1.0.0. Please check the property sonar.sources -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project <project>: The directory '/<dir>/<user>/<dir>/<projectRoot>/cache/module1/src' does not exist for Maven module com.<project>:cache:jar:1.0.0. Please check the property sonar.sources
One of my maven modules is called cache but I am not sure whether this is connected.
the non-mvn-module-directory is not part of the maven project at all, right?
Is there a root pom? In which pom.xml did you specify <sonar.sources>?
I’m having trouble understanding the structure of your project.
Correct, non-mvn-module-directoy has no pom.xml itself but contains files I’d like to be scanned. I specify the <sonar.sources> in the root pom.xml file.
Hi,
Sorry for the late reply. If I remember correctly, properties are always inherited in maven. I think the problem you’re facing is that all modules are using the sonar.sources that you set in the root module.
I suggest you either override sonar.sources in the specific module where you want to include the sources of non-mvn-module-directory. If it has submodules, you’ll have to define sonar.sources in those submodules as well to point to the correct directories.