Skip to content

Fix SonarQube analysis: file indexed twice error in dispatcher-agent #762

Description

@bedaHovorka

Problem

SonarQube analysis is failing during the sonar Gradle task with the following error:

File dispatcher-agent/src/main/kotlin/cz/vutbr/fit/interlockSim/dispatcher/DispatchDecisionApplier.kt 
can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for 
main and test files

This occurs in the .github/workflows/sonarqube.yml workflow (job #86623950861).

Root Cause

SonarQube is encountering the same Kotlin file in both main source and test source paths, causing a conflict during analysis. The sonar Gradle task is unable to resolve overlapping source/test directories.

Solution

Configure SonarQube's source inclusion/exclusion patterns in the build.gradle.kts to ensure main and test files don't overlap.

Add the following to your sonar configuration block:

sonar {
    properties {
        property("sonar.sources", "src/main")
        property("sonar.tests", "src/test")
        property("sonar.sourceEncoding", "UTF-8")
    }
}

Verification Steps

  1. Ensure the project structure has main sources in src/main/kotlin/ and test files in src/test/kotlin/
  2. Verify that no Kotlin files are duplicated between main and test source trees
  3. Trigger the SonarQube workflow manually or via a new push to verify the fix

Related Workflow

  • .github/workflows/sonarqube.yml - SonarCloud analysis workflow
  • Triggered by: .github/workflows/gradle-java21.yml completion

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions