Unable to scan when project key and artifact name are the same

Must-share information (formatted with Markdown):

  • which versions are you using: maven sonar 3.11.0.3922

Using maven sonar plugin we are encountering an issue when the sonar projectKey and the artifact name are the same. This is a multi module maven project with one module.

Project key: com.foo.bar:baz
Artifact name: baz

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar (default-cli) on project baz-parent: Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@35fddea2-org.sonar.scanner.scan.ModuleIndexer': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DefaultInputModuleHierarchy' defined in org.sonar.scanner.scan.InputModuleHierarchyProvider: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sonar.scanner.scan.DefaultInputModuleHierarchy]: Factory method 'provide' threw exception; nested exception is java.lang.StackOverflowError -> [Help 1]

It’s not clear to us where the breakdown is happening. If we rename the artifact name to baz1 it is able to scan.

Hi,

Welcome to the community and thanks for this report!

Could we have the full analysis log, starting from the analysis command?

 
Thx,
Ann

Thank you for the response. Here is the full log:

 mvn -B sonar:sonar -DskipTests=true -Dsonar.host.url=https://sonar.foo.com/sonar \
-Dsonar.projectKey=com.foo.bar:baz -Dsonar.projectBaseDir=foo \
 -Dsonar.sources=src/main -Dsonar.java.binaries=target/classes \
 -Dsonar.language=java -Dsonar.branch.name=feature/sonarDebug \
-Dsonar.login=**********
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] baz-parent                                                       [pom]
[INFO] baz                                                              [jar]
[INFO] 
[INFO] -------------------< com.foo.bar:baz-parent >--------------------
[INFO] Building baz-parent 2.2.0                                        [1/2]
[INFO]   from pom.xml
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- sonar:3.11.0.3922:sonar (default-cli) @ baz-parent ---
...
[INFO] 15:34:51.775 Default locale: "en_US", source code encoding: "UTF-8"
[INFO] 15:34:51.997 Load global settings
[INFO] 15:34:52.495 Load global settings (done) | time=497ms
...
[INFO] 15:34:52.503 Load/download plugins
[INFO] 15:34:52.503 Load plugins index
[INFO] 15:34:52.618 Load plugins index (done) | time=115ms
[INFO] 15:34:52.998 Load/download plugins (done) | time=495ms
[INFO] 15:34:53.108 Loaded core extensions: developer-scanner
[INFO] 15:34:53.507 Process project properties
[INFO] 15:34:53.513 Process project properties (done) | time=6ms
[INFO] 15:34:53.514 Execute project builders
[INFO] 15:34:53.514 Execute project builders (done) | time=0ms
[INFO] 15:34:53.516 Project key: com.foo.bar:baz
[INFO] 15:34:53.516 Base dir: /Users/USER/code/id-bar-baz
[INFO] 15:34:53.516 Working dir: /Users/USER/code/id-bar-baz/target/sonar
[INFO] 15:34:53.520 Load project settings for component key: 'com.foo.bar:baz'
[INFO] 15:34:53.629 Load project settings for component key: 'com.foo.bar:baz' (done) | time=109ms
[INFO] 15:34:53.667 Load project branches
[INFO] 15:34:53.770 Load project branches (done) | time=104ms
[INFO] 15:34:53.770 Load branch configuration
[INFO] 15:34:53.770 Found manual configuration of branch/PR analysis. Skipping automatic configuration.
[INFO] 15:34:53.771 Load branch configuration (done) | time=1ms
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for baz-parent 2.2.0:
[INFO] 
[INFO] baz-parent ....................................... FAILURE [  3.860 s]
[INFO] baz .............................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.118 s
[INFO] Finished at: 2024-05-15T15:34:53-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven- plugin:3.11.0.3922:sonar 
(default-cli) on project baz-parent: Error creating bean with name
 'org.sonarsource.scanner.api.internal.IsolatedClassloader@35fddea2-org.sonar.scanner.scan.ModuleIndexer': 
Unsatisfied dependency expressed through constructor parameter 1; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'DefaultInputModuleHierarchy' defined in
org.sonar.scanner.scan.InputModuleHierarchyProvider: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.sonar.scanner.scan.DefaultInputModuleHierarchy]: 
Factory method 'provide' threw exception; 
nested exception is java.lang.StackOverflowError -> [Help 1]

Hi,

Thanks for the log.

I notice you include multiple properties in your analysis command which are normally read automatically from the Maven environment. To eliminate variables can you try it with a pared-down command?

mvn -B sonar:sonar-Dsonar.host.url=https://sonar.foo.com/sonar -Dsonar.projectKey=com.foo.bar:baz -Dsonar.branch.name=feature/sonarDebug -Dsonar.login=**********

For the ones I’ve removed here^:

  • -DskipTests=true not needed since you’re only doing analysis and analysis doesn’t fire tests
  • -Dsonar.projectBaseDir=foo typically, this is the directory from which analysis is invoked. If you really need this, we should examine the circumstances
  • -Dsonar.sources=src/main read from the Maven env
  • -Dsonar.java.binaries=target/classes ditto
  • -Dsonar.language=java this does nothing, and hasn’t for a very long time
  • -Dsonar.branch.name=feature/sonarDebug this is normally picked up from the environment, but maybe you haven’t actually checked out a branch this time?

 
Thx,
Ann

Thank you for the suggestion, tried the pared down args and unfortunately getting the same result.

Found this semi-related issue: StackOverflowError at DefaultInputComponent.equals - #5 by Andrew_Swan

The suggestion there was to add sonar.moduleKey . If I add that with the name of the module it appears to work:

mvn -B sonar:sonar -Dsonar.moduleKey=baz 
 -Dsonar.host.url=https://sonar.foo.com/sonar 
-Dsonar.projectKey=com.foo.bar:baz -Dsonar.projectBaseDir=gaf 
-Dsonar.sources=src/main -Dsonar.java.binaries=target/classes 
-Dsonar.branch.name=feature/sonarDebug -Dsonar.login=****
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] baz-parent                                                       [pom]
[INFO] baz                                                              [jar]
[INFO] 
[INFO] -------------------< com.foo.bar:baz-parent >--------------------
[INFO] Building baz-parent 2.2.0                                        [1/2]
[INFO]   from pom.xml
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- sonar:3.11.0.3922:sonar (default-cli) @ baz-parent ---
...
[INFO] 15:08:59.306 User cache: /Users/USER/.sonar/cache
[INFO] 15:08:59.307 Load/download plugins
[INFO] 15:08:59.307 Load plugins index
[INFO] 15:08:59.425 Load plugins index (done) | time=118ms
[INFO] 15:08:59.527 Load/download plugins (done) | time=220ms
[INFO] 15:08:59.624 Loaded core extensions: developer-scanner
[INFO] 15:08:59.838 Process project properties
[INFO] 15:08:59.843 Process project properties (done) | time=5ms
[INFO] 15:08:59.844 Execute project builders
[INFO] 15:08:59.844 Execute project builders (done) | time=0ms
[INFO] 15:08:59.867 Project key: com.foo.bar:baz
[INFO] 15:08:59.868 Base dir: /Users/USER/code/asd-bar-baz
[INFO] 15:08:59.868 Working dir: /Users/USER/code/asd-bar-baz/target/sonar
[INFO] 15:08:59.872 Load project settings for component key: 'com.foo.bar:baz'
[INFO] 15:09:00.001 Load project settings for component key: 'com.foo.bar:baz' (done) | time=129ms
[INFO] 15:09:00.043 Load project branches
[INFO] 15:09:00.155 Load project branches (done) | time=112ms
[INFO] 15:09:00.155 Load branch configuration
[INFO] 15:09:00.156 Found manual configuration of branch/PR analysis. Skipping automatic configuration.
[INFO] 15:09:00.156 Load branch configuration (done) | time=1ms
[INFO] 15:09:00.217 Load quality profiles
[INFO] 15:09:00.366 Load quality profiles (done) | time=149ms
[INFO] 15:09:00.369 Load active rules
[INFO] 15:09:08.919 Load active rules (done) | time=8550ms
[INFO] 15:09:08.921 Load analysis cache
[INFO] 15:09:09.040 Load analysis cache | time=119ms
[INFO] 15:09:09.064 Branch name: feature/sonarDebug
[INFO] 15:09:09.072 Load project repositories
[INFO] 15:09:09.184 Load project repositories (done) | time=112ms
[INFO] 15:09:09.201 Indexing files...
[INFO] 15:09:09.202 Project configuration:
[INFO] 15:09:09.340 Indexing files of module 'baz'
[INFO] 15:09:09.340   Base dir: /Users/USER/code/asd-bar-baz/gaf
[INFO] 15:09:09.344   Source paths: src/main
[INFO] 15:09:09.344   Test paths: src/test/java
[INFO] 15:09:09.368 Indexing files of module 'baz-parent'
[INFO] 15:09:09.368   Base dir: /Users/USER/code/asd-bar-baz
...
[INFO] 15:09:13.840 Analysis report generated in 175ms, dir size=408.7 kB
[INFO] 15:09:13.903 Analysis report compressed in 63ms, zip size=158.8 kB
[INFO] 15:09:14.258 Analysis report uploaded in 355ms
[INFO] 15:09:14.260 ANALYSIS SUCCESSFUL, you can find the results at: https://sonar.foo.com/sonar/dashboard?id=com.foo.bar%3Abaz&branch=feature%2FsonarDebug
[INFO] 15:09:14.260 Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] 15:09:14.260 More about the report processing at https://sonar.foo.com/sonar/api/ce/task?id=AY-H9VjhPyq_0Gd5Ao7i
[INFO] 15:09:14.287 Analysis total time: 14.663 s
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for baz-parent 2.2.0:
[INFO] 
[INFO] baz-parent ....................................... SUCCESS [ 17.712 s]
[INFO] baz .............................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.995 s
[INFO] Finished at: 2024-05-17T15:09:14-04:00

Hi,

I’m wondering if this is relevant:

SCANMAVEN-205 Undesired behaviour when sonar.projectKey is specified in root pom or as user property

Can you try it without specifying sonar.projectKey on the command line? Just let the scanner pick it up from your POM values.

 
Thx,
Ann

Our pattern is to pass in sonar projectKey through cli so unfortunately that won’t be an option for us

Hi,

I’m asking if you can try it to move the debugging along, please.

 
Thx,
Ann

Sorry I wasn’t clearer in my previous message. I meant that its not possible for us to not specify the project key because if we rely on the default it will use a sonar key that does not exist.

Exists (need to inject through projectKey): com.bar.foo:baz
Does not exist (default projecyKey if not set): com.bar.foo:baz-parent

Hi,

Okay, yeah. I get that. Can you try it once anyway or will that screw up your license LOC?

 
Thx,
Ann

We have one project that at the moment has a project key for baz and baz-parent. If I don’t specify projectKey on cli it is able to scan.

We think that adding moduleKey seems to be the best way to work around the bug for now

1 Like

Hi,

Thanks for confirming. I’ve noted this thread in the ticket. Maybe that will give it a little more weight & momentum.

 
Ann

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.