Can't be indexed twice - a file from sonar.tests folder

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube: 9.9.0.65466, SonarScanner: 4.8.0.2856)
  • how is SonarQube deployed: zip

I’m trying to set the sources and tests folders, here is part of my configuration:
sonar.tests=test/
sonar.sources=database/

ERROR: File test/arc/init.py can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for the main and test files

Any idea why “test/arc/init.py” is indexed twice?

Hi,

Welcome to the community!

Can you share your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

sonarqube.log (30.5 KB)

I have shortened logs to reduce the length and because of privacy.

Thank you
Mislav

Hi,

I’m not seeing what I hoped to here. Can you also share the scanner context? You find it under Project Settings → Background Tasks → [analysis row cog menu]

 
Thx,
Ann

Unfortunately, the task which is failing is not listed in " Background Tasks".

Hi,

Of course it’s not. Don’t know where my head was. You can get a concise list of the properties analysis ran with by adding -Dsonar.scanner.dumpToFile=[file path] to the analysis command line.

 
Ann

sonarqube.txt (2.7 KB)

Here it is.

Also, now there is the warning:
##[warning]No analyses found in this build! Please check your build configuration.

Thanks
Mislav

Hi Mislav,

Here’s what I see:

sonar.projectBaseDir=/home/sesadm/myagent/_work/3/s
sonar.sources=/home/sesadm/myagent/_work/3/s
sonar.tests=test/

I don’t know whether you’re explicitly setting sonar.sources to your project base directory, or letting it default there, but the effect is to say every file in the project is a source file.

You then additionally specify a subset as tests, which is where the “indexed twice” error comes from: the files are being registered as both sources and tests.

So you should either narrow your sonar.sources specification, or add your tests directory to your exclusions:

sonar.exclusions=**/*.json,legacy_mini_arc/**,kafka/**,docker/**

 
HTH,
Ann

Thanks Ann for explaining this.

I have in sonar-project.properties:

sonar.sources=database/

Hence, I would expect instead:

sonar.sources=/home/sesadm/myagent/_work/3/s

To have:

sonar.sources=/home/sesadm/myagent/_work/3/s/database/

Hi,

The document you posted should be exactly the values that the scanner ran with. So if you’re seeing something different than you expect, there’s some detective work to be done to figure out where the unexpected values came from. The docs explain the hierarchy.

 
HTH,
Ann

Hi Ann,

Thanks to you I found what issue was.

It runs Azure DevOps and sources must be defined to pipeline file like this:

steps:
- checkout: self
  fetchDepth: 0
- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'SonarQube'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: '<KEY>'
    cliSources: 'database/'

Test folders are still defined inside ‘sonar-project.properties’ file like this

sonar.tests=test/

Documentation:

Thanks
Mislav

1 Like

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