Sonar plugin 4.3.0.3225 error

After updating from 4.2.1.31684.3.0.3225 the sonar task fails with the following message:

File common/common-android/common-android.gradle.kts can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

We apply the sonar plugin to the root project and each subproject.

This error is probably caused by SONARGRADL-120 Add .gradle.kts files to the sonar.sources (#182) · SonarSource/sonar-scanner-gradle@2a927d3 · GitHub

I assume that

project.getAllprojects().stream()
.map(Project::getBuildFile)

will add all subproject build script files to the root project file list and each submodule will add it’s own build script again? Maybe that is the issue?

Our Setup:
Gradle 8.2.1
Android Plugin 8.0.2
BellSoft OpenJDK Runtime Environment 17.0.7

4 Likes

I’m getting the same error, even though the SonarQube plugin is only applied to the root project:

Execution failed for task ‘:sonar’.
File sonar-zpa-plugin/build.gradle.kts can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

1 Like

I’m having the same problem. I only have a root project and one module.
and I don’t have sonar.sources or sonar.tests set up.

File stream/amazon-image-remover/build.gradle.kts can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

According to the documentation, the default values for sonar.sources and sonar.tests are ${sourceSets.main.allJava.srcDirs}
However, when I tested it with the code below, the result was different

task("sonarSrcTest") {
    println(this.project.sourceSets.main.get().allJava.srcDirs)
    println(this.project.sourceSets.test.get().allJava.srcDirs)
}

// sonarSrcTest result
print sonar sources
[/Users/user/Desktop/hyotaek/line/programming/media/src/main/java, /Users/user/Desktop/hyotaek/line/programming/media/src/main/kotlin]

print sonar tests
[/Users/user/Desktop/hyotaek/line/programming/media/src/test/java, /Users/user/Desktop/hyotaek/line/programming/media/src/test/kotlin]
# sonar version : 4.3.0.3225
subprojects{
    sonar {
        this.properties {
            println("print sonar sources")
            println(properties["sonar.sources"])
            println("print sonar tests")
            println(properties["sonar.tests"])
        }
    }
}

# root sonar result
print sonar sources
[/Users/user/Desktop/hyotaek/line/programming/media/stream/build.gradle.kts, /Users/user/Desktop/hyotaek/line/programming/media/stream/amazon-image-remover/build.gradle.kts]
print sonar tests
null

# submodule sonar result
print sonar sources
[/Users/user/Desktop/hyotaek/line/programming/media/stream/amazon-image-remover/build.gradle.kts, /Users/user/Desktop/hyotaek/line/programming/media/stream/amazon-image-remover/src/main/kotlin]
print sonar tests
[/Users/user/Desktop/hyotaek/line/programming/media/stream/amazon-image-remover/src/test/kotlin]

Finally, below are the results of running the same sonar task with version 4.2.1.3168

# root sonar result
print sonar sources
null
print sonar tests
null

# submodule sonar result
print sonar sources
[/Users/user/Desktop/hyotaek/line/programming/media/stream/amazon-image-remover/src/main/kotlin]
print sonar tests
[/Users/user/Desktop/hyotaek/line/programming/media/stream/amazon-image-remover/src/test/kotlin]

Hello @G00fY2 @felipebz @felipebz,

Thanks for your reports.

Could you please run the sonar command with this flag -Dsonar.scanner.dumpToFile= path/to/some/file And share the content of that file here? So I can investigate the issue.

Meanwhile, you can use the older version of the scanner or exclude the problematic file within sonar. exclusions property.

Regards,
Margarita

1 Like

Hello MargaritaNedzelska,

I will deliver the file via the command you requested.

sonarDump.txt (99.2 KB)

Thank you

1 Like

@HyoTaek-Jang

Thanks for your input, I found the root cause of the issue. Here’s the ticket for this bug:

https://sonarsource.atlassian.net/browse/SONARGRADL-126

Meanwhile, you can use the previous version of the plugin.

Regards,
Margarita

2 Likes

We added

property(“sonar.exclusions”, “**/*.gradle.kts”)

to the root project, so we don’t need to downgrade. Looking forward to the fix.

5 Likes

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

@G00fY2 @felipebz @HyoTaek-Jang just wanted let you know, that the new version of the Gradle plugin is out, and you don’t need to exclude the .gradle.kts files anymore.

If you face any other problems, please create a new thread in our community forum.

Best,
Margarita

2 Likes