How to scan non-maven modules

I have a maven project with such structure:

- module1
- module2
- non-mvn-module-directory

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?

Hi,

Welcome to the community!

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.

 
HTH,
Ann

Hi Ann,

Thanks for your reply!

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?

Best,
Ivan

Hi Ivan,

Could you provide the analysis logs, redacted as necessary?

 
Ann

[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.

Hi,

Could we have the whole log - redacted as necessary - starting from the analysis command?

 
Ann

-Dsonar.sources=module1/src,module2/src,non-mvn-module/src

[INFO] Scanning for projects…
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] project-name [pom]
[INFO] cache [jar]
[INFO] module1 [jar]
[INFO] module2 [jar]
[INFO] module3 [jar]
[INFO] tests-result-aggregator [jar]
[WARNING] The artifact org.codehaus.mojo:sonar-maven-plugin:jar:3.9.1.2184 has been relocated to org.sonarsource.scanner.maven:sonar-maven-plugin:jar:3.9.1.2184: SonarQube plugin was moved to SonarSource organisation
[INFO]
[INFO] --------------< com.package.project-name:project-name >--------------
[INFO] Building 1.0.0 [1/20]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] — sonar-maven-plugin:3.9.1.2184:sonar (default-cli) @ —
[INFO] User cache: /Users/user/.sonar/cache
[INFO] SonarQube version: 8.9.9
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] project-name 1.0.0 … FAILURE [ 3.385 s]
[INFO] cache 1.0.0 … SKIPPED
[INFO] module1 1.0.0 … SKIPPED
[INFO] module2 1.0.0 … SKIPPED
[INFO] module3 1.0.0 … SKIPPED
[INFO] tests-result-aggregator 1.0.0 … SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.051 s
[INFO] Finished at: 2022-10-11T19:09:03+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project : The directory ‘/Users/user/dir/dir/cache/module1/src’ does not exist for Maven module com.package.project-name:cache:jar:1.0.0. Please check the property sonar.sources → [Help 1]

Hi,

Thanks for the log. I’ve referred this for more expert eyes.

 
Ann

Thanks, Ann! Looking forward to hearing back from you.

Hi,

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.

Hi Duarte,

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.