Skip to content

Commit dba4fe5

Browse files
authored
Fix SonarQube "indexed twice" error for dispatcher-agent sources (#763)
* Fix SonarQube double-indexing: move dispatcher-agent sonar config to subproject The SonarQube Gradle plugin v6+ auto-detects JVM subproject source sets. Having dispatcher-agent paths in BOTH the root sonar {} block AND the subproject's auto-detected sources caused: "File ... can't be indexed twice" (Issue #762) Fix: - Remove dispatcher-agent/src/{main,test}/kotlin from root sonar.sources/ sonar.tests and java binary paths in build.gradle.kts - Add explicit sonar {} block in dispatcher-agent/build.gradle.kts that claims src/main/kotlin and src/test/kotlin for this module - Update sonar-project.properties to include dispatcher-agent paths for consistency with CLI sonar-scanner runs
1 parent cd651b1 commit dba4fe5

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

build.gradle.kts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,23 @@ sonar {
101101
property("sonar.projectName", "interlockSim - Railway Interlocking Simulator")
102102
property("sonar.projectVersion", version.toString())
103103

104-
// Source and test paths (desktop-ui + :core KMP subproject + :dispatcher-agent).
104+
// Source and test paths (desktop-ui + :core KMP subproject).
105+
// :dispatcher-agent sources/tests are configured in dispatcher-agent/build.gradle.kts
106+
// via its own sonar {} block to avoid double-indexing (SonarQube Gradle plugin v6
107+
// auto-detects JVM subproject source sets; listing them here AND in the subproject
108+
// causes "can't be indexed twice" errors — Issue #762).
105109
// Kept in sync with sonar-project.properties (used for local sonar-scanner runs).
106110
property(
107111
"sonar.sources",
108112
"desktop-ui/src/main/kotlin,core/src/commonMain/kotlin," +
109-
"core/src/jvmMain/kotlin,core/src/nativeMain/kotlin," +
110-
"dispatcher-agent/src/main/kotlin",
113+
"core/src/jvmMain/kotlin,core/src/nativeMain/kotlin",
111114
)
112115
property(
113116
"sonar.tests",
114-
"desktop-ui/src/test/kotlin,core/src/commonTest/kotlin,core/src/jvmTest/kotlin," +
115-
"dispatcher-agent/src/test/kotlin",
117+
"desktop-ui/src/test/kotlin,core/src/commonTest/kotlin,core/src/jvmTest/kotlin",
116118
)
117-
property("sonar.java.binaries", "desktop-ui/build/classes/kotlin/main,core/build/classes/kotlin/jvm/main,dispatcher-agent/build/classes/kotlin/main")
118-
property("sonar.java.test.binaries", "desktop-ui/build/classes/kotlin/test,core/build/classes/kotlin/jvm/test,dispatcher-agent/build/classes/kotlin/test")
119+
property("sonar.java.binaries", "desktop-ui/build/classes/kotlin/main,core/build/classes/kotlin/jvm/main")
120+
property("sonar.java.test.binaries", "desktop-ui/build/classes/kotlin/test,core/build/classes/kotlin/jvm/test")
119121

120122
property("sonar.java.source", javaVersion)
121123
property("sonar.java.target", javaVersion)

dispatcher-agent/build.gradle.kts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,26 @@ tasks.named<JacocoReport>("jacocoTestReport") {
206206
dependencies {
207207
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.7")
208208
}
209+
210+
// ===========================================
211+
// SonarQube per-module configuration
212+
// ===========================================
213+
//
214+
// The SonarQube Gradle plugin v6+ auto-detects source sets for every Kotlin JVM
215+
// subproject. If the root build.gradle.kts ALSO lists this module's source paths in
216+
// sonar.sources / sonar.tests, the same files get indexed twice, causing:
217+
// "File ... can't be indexed twice. Please check that inclusion/exclusion patterns
218+
// produce disjoint sets for main and test files" (Issue #762)
219+
//
220+
// Fix: declare sources/tests explicitly here so the scanner uses ONLY this configuration
221+
// for the :dispatcher-agent module. The root sonar{} block intentionally omits these paths.
222+
223+
sonar {
224+
properties {
225+
property("sonar.sources", "src/main/kotlin")
226+
property("sonar.tests", "src/test/kotlin")
227+
property("sonar.java.binaries", "build/classes/kotlin/main")
228+
property("sonar.java.test.binaries", "build/classes/kotlin/test")
229+
property("sonar.sourceEncoding", "UTF-8")
230+
}
231+
}

sonar-project.properties

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ sonar.projectVersion=1.0
1212
# Organization (required for SonarCloud)
1313
sonar.organization=bedahovorka
1414

15-
# Source code location (Kotlin; :core KMP subproject + :desktop-ui JVM subproject)
16-
sonar.sources=desktop-ui/src/main/kotlin,core/src/commonMain/kotlin,core/src/jvmMain/kotlin,core/src/nativeMain/kotlin
15+
# Source code location (Kotlin; :core KMP subproject + :desktop-ui JVM subproject + :dispatcher-agent)
16+
sonar.sources=desktop-ui/src/main/kotlin,core/src/commonMain/kotlin,core/src/jvmMain/kotlin,core/src/nativeMain/kotlin,dispatcher-agent/src/main/kotlin
1717
# sonar.tests: no nativeTest entry yet — add core/src/nativeTest/kotlin here
1818
# if native test sources are introduced (keeps symmetry with nativeMain above).
19-
sonar.tests=desktop-ui/src/test/kotlin,core/src/commonTest/kotlin,core/src/jvmTest/kotlin
19+
sonar.tests=desktop-ui/src/test/kotlin,core/src/commonTest/kotlin,core/src/jvmTest/kotlin,dispatcher-agent/src/test/kotlin
2020

2121
# Source encoding — UTF-8 is the project default (see .editorconfig).
2222
sonar.sourceEncoding=UTF-8
@@ -25,18 +25,18 @@ sonar.sourceEncoding=UTF-8
2525
sonar.java.source=21
2626
sonar.java.target=21
2727

28-
# Binary locations (compiled classes — dual-module).
28+
# Binary locations (compiled classes — multi-module).
2929
# Native (linuxX64) compilations are intentionally excluded: SonarCloud's
3030
# Kotlin analyzer operates from sources, and java.binaries is JVM-only.
31-
sonar.java.binaries=desktop-ui/build/classes/kotlin/main,core/build/classes/kotlin/jvm/main
32-
sonar.java.test.binaries=desktop-ui/build/classes/kotlin/test,core/build/classes/kotlin/jvm/test
31+
sonar.java.binaries=desktop-ui/build/classes/kotlin/main,core/build/classes/kotlin/jvm/main,dispatcher-agent/build/classes/kotlin/main
32+
sonar.java.test.binaries=desktop-ui/build/classes/kotlin/test,core/build/classes/kotlin/jvm/test,dispatcher-agent/build/classes/kotlin/test
3333

3434
# Library dependencies (optional - helps with better analysis)
3535
# sonar.java.libraries=build/libs/*.jar,~/.m2/repository/**/*.jar
3636

37-
# Test execution and coverage reports (dual-module)
38-
sonar.junit.reportPaths=desktop-ui/build/test-results/test,desktop-ui/build/test-results/integrationTest,core/build/test-results/jvmTest,core/build/test-results/integrationTest
39-
sonar.coverage.jacoco.xmlReportPaths=desktop-ui/build/reports/jacoco/test/jacocoTestReport.xml,core/build/reports/jacoco/jvmTest/jacocoTestReport.xml
37+
# Test execution and coverage reports (multi-module)
38+
sonar.junit.reportPaths=desktop-ui/build/test-results/test,desktop-ui/build/test-results/integrationTest,core/build/test-results/jvmTest,core/build/test-results/integrationTest,dispatcher-agent/build/test-results/test,dispatcher-agent/build/test-results/integrationTest
39+
sonar.coverage.jacoco.xmlReportPaths=desktop-ui/build/reports/jacoco/test/jacocoTestReport.xml,core/build/reports/jacoco/jvmTest/jacocoTestReport.xml,dispatcher-agent/build/reports/jacoco/test/jacocoTestReport.xml
4040

4141
# Project links (optional - useful for GitHub integration)
4242
# sonar.links.homepage=https://github.com/bedaHovorka/interlockSim

0 commit comments

Comments
 (0)