Scanner for Maven: files indexed twice using the "sonar.maven.scanAll"

Nice, the new version has been released !

However with sonar.maven.scanAll=true, our build throws an error that the scanner tries to index mutiple times the same maven files.

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar (default-cli) on project foo-parent: File parent/pom.xml can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]

I guess that if we exclude maven related files, it wont scan java files anymore right ?

I’ll look for a workaround and post it here if I find one.

1 Like

Hello,

Thanks for this quick feedback. That’s great to a such an engaged community.

Can you share the structure of your project and the full log so we can understand what we missed?

Thanks
Alex

Hi @ggjulio,
Can you confirm if you have explicitly set sonar.inclusions or sonar.tests? I think these are 2 of the parameters we might have missed.

Cheers

Thanks a lot Alexandre and Dorian for theses fast replies.

@Dorian_Burihabwa , we don’t use any sonar.inclusions or sonar.tests in our settings.
Should we ?

@Alexandre_Gigleux I wont be able to provide any log files.
However, we use a parent pom. ( Maven – Introduction to the POM )
And we run sonar that way:

mvn -s settings-sonar.xml -f ./parent sonar:sonar \
   -Dsonar.maven.scanAll=true \
   [other redacted params]...

I guess what’s happening, is that the option scanAll is not aware of -f parent and tries to scan parent/pom.xml a second time.

When we execute it without -f ./parent, the scan runs fine. (because it uses the “root” pom)
But unfortunately we can’t just do that because it omits several of our modules.

I didn’t got the time yet to try some workarounds.
Any hints welcomed !

Thank you

1 Like

Hey @ggjulio,
Thank you for clarifying. Unfortunately, I cannot reproduce the issue because I am still missing some information. Namely,

  1. Project architecture: Is the parent module a sibling of all the modules that depend on it and the root folder does not contain a pom?
root/
  parent/
    pom.xml
  child1/
    pom.xml <-- points to parent as parent project
  child2/
    pom.xml <-- points to parent as parent project
  1. Analysis scope: Are you trying to restrict the analysis to the parent module? Or to analyze all modules in the root?

If you think providing a minimal example as an archive, feel free to share this with us.

Cheers,

Dorian

Sorry, I now realize that I did not look at the link you posted earlier. I will have a look at that and come back to you!

It seem we got it working.

To avoid the error parent/pom.xml can't be indexed twice,
We moved our sonar settings from parent/pom.xml into our settings.xml
(it seem that since 7.6 we should not put the sonar profile config inside the pom anymore)

Next week we’ll to compare reports more in depth.
But it seem fine so far.

Thanks a lot !

Useful links :

EDIT

Well, what fixed the error was not the fact that we moved the sonar settings outside the pom…
But rather the fact that we modified mvn -f ./parent to mvn -f parent (notice the ./ )
It’s weird, but it works…

2 Likes