Java can't be indexed twice

Must-share information (formatted with Markdown):
I m using sonarqube-gradle-plugin:3.3 version and trying to scan a Java project through GitHub Action. I have set the sources and tests file but I encountered the issue regarding some files cannot be indexed twice.
The structure of my java project is:
├── api-model
│ └── src
│ ├── main
│ │ ├── java
│ │ └── pegasus
│ └── test
│ └── java
├── client
│ └── src
│ ├── main
│ │ └── java
│ └── test
│ ├── java
│ └── resources
├── client-tools
│ ├── binding-generator
│ │ └── src
│ │ ├── main
│ │ └── test
│ ├── client-generator
│ │ └── src
│ │ ├── main
│ │ └── test
│ └── query-builder
│ └── src
│ ├── main
│ └── test
├── datafetcher-generator
│ └── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
│ ├── java
│ └── resources

Here’re the things I have tried:

  1. I tried to NOT specify sources and tests in the gradle setting and just let the gradle plugin to auto detect that according Narrowing the focus with analysis scope. It could be auto detected and what I got is graphql-infra/graphql-infra/api-model/src/test/java/com/graphql/api/GraphQLResponseUtilTest.java can’t be indexed twice.
  2. I also tried to just set
    sources=datafetcher-generator/src/main/java
    tests=datafetcher-generator/src/test/java
    but it also complains raphql-infra/graphql-infra/api-model/src/test/java/com/graphql/api/GraphQLResponseUtilTest.java can’t be indexed twice. It’s weird since I don’t even include that in the sources.
  3. I tried the wild card which is to set
    sources=/src/main/java
    tests=
    /src/test/java.
    It complains graphql-infra/graphql-infra/api-model/src/test/java/com/graphql/api/GraphQLResponseUtilTest.java can’t be indexed twice.
  4. I tried to use inclusion and exclusion.

Seems like nothing works. And it felt weird that the scanner doesn’t seem to pick up my settings. Could anyone please help?

Hey there.

I would suggest making sure to not specify sources and tests if you’re using the Scanner for Gradle.

It also specifies how sonar.sources and sonar.tests are derived by default.

sonar.sources ${sourceSets.main.allJava.srcDirs} (filtered to only include existing directories)
sonar.tests ${sourceSets.test.allJava.srcDirs} (filtered to only include existing directories)

Is it possible that, for example, graphql-infra/graphql-infra/api-model/src/test/java/com/graphql/api/GraphQLResponseUtilTest.java exists under both ${sourceSets.main.allJava.srcDirs} and ${sourceSets.test.allJava.srcDirs}?