Skip to content

JACOCO-241 Don't count Kotlin scripts as files coverable by JaCoCo - #342

Open
henryju wants to merge 1 commit into
masterfrom
jh/JACOCO-241-ignore-kotlin-scripts
Open

henryju wants to merge 1 commit into
masterfrom
jh/JACOCO-241-ignore-kotlin-scripts

Conversation

@henryju

@henryju henryju commented Oct 16, 2026

Copy link
Copy Markdown
Member

JACOCO-241 Don't count Kotlin scripts (.kts) as files coverable by JaCoCo, to remove a false "could not be matched" warning on the root module of Gradle Kotlin DSL builds.

Problem

The SonarScanner for Gradle adds the build scripts of the whole build (build.gradle.kts, settings.gradle.kts) to the sources of the root module. The Kotlin analyzer indexes them as kotlin MAIN files, so FileLocator.hasFilesCoverableByJacoco() returned true. In most multi-module setups the root module also inherits sonar.coverage.jacoco.xmlReportPaths. A Gradle script never appears in a JaCoCo report, so nothing matched, and every analysis got:

  • the WARN None of the N files in coverage report '...' could be matched to the analysed sources of '<root>'. No coverage was imported from this report.
  • the analysis warning SensorUtils.NOTHING_MATCHED_ANALYSIS_WARNING, shown in the UI.

Fix

FileLocator.isCoverableByJacoco now ignores files whose name ends with .kts (case-insensitive). The change only affects the coverable count used to choose between the WARN + analysis warning and the DEBUG log (introduced by JACOCO-175). Matching, importing and the indexing of the path tree are unchanged. A module whose only Kotlin files are scripts now gets the DEBUG log of modules without coverable files, and no analysis warning.

Tests

  • FileLocatorTest: a locator with only .kts Kotlin MAIN files (including an upper-case .KTS) has no coverable files. With a .kt file next to them, it has some.
  • SensorUtilsTest (real ModuleFileLocator): a module with only build.gradle.kts/settings.gradle.kts that imports a report matching nothing logs at DEBUG, with no WARN and no analysis warning. A module with a .kt file still gets the WARN and NOTHING_MATCHED_ANALYSIS_WARNING.
  • IT JacocoTest.should_not_warn_when_the_only_kotlin_files_are_gradle_scripts: new kotlin-gradle-scripts-project fixture, analysed with SonarScanner CLI, sonar.sources=build.gradle.kts,settings.gradle.kts and sonar.coverage.jacoco.xmlReportPaths=jacoco.xml. It checks that the DEBUG log is there, that there's no "could be matched" log, and that api/ce/analysis_status reports no JaCoCo warning.

ITs ran locally with -Dsonar.runtimeVersion=LATEST_RELEASE: all 13 pass. Without the fix, the new IT fails as expected (it logs None of the 2 files in coverage report ... could be matched). ./gradlew build passes.

🤖 Generated with Claude Code

The SonarScanner for Gradle adds the Kotlin build scripts of the whole
build to the sources of the root module. Kotlin scripts are never in a
JaCoCo report, so a root module that inherits an XML report path matched
nothing and raised a WARN and an analysis warning on every analysis.
Kotlin scripts (.kts) no longer count as coverable files, so such a
module gets the DEBUG log of modules without coverable files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

JACOCO-241

@gitar-bot

gitar-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Changing JaCoCo file eligibility for .kts modules alters whether unmatched-report warnings appear, potentially masking report/source mismatches in script-only modules.

Excludes Kotlin scripts (.kts, case-insensitive) from the JaCoCo coverable-file count in FileLocator.isCoverableByJacoco, so Gradle Kotlin DSL root modules no longer emit a false "could not be matched" warning. No issues found.

Verification Rules 2/2 met PRs 1 inspected

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries (artifactory_registries)
✅ Repository license compliance (license_compliance)

Broader impact PRs 1 inspected
Cross-PR 1 PR inspected 0 open impacts

PR #343: JACOCO-240 Skip the module sensor when the module has no main file Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown

@henryju
henryju marked this pull request as ready for review October 16, 2026 14:24
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 7 days with no activity. If there is no activity in the next 7 days it will be closed automatically

@github-actions github-actions Bot added the stale label Oct 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant