intellij-platform-gradle-plugin
intellij-platform-gradle-plugin copied to clipboard
Auto-generated classes show no coverage with jacoco after upgrading to `1.13.3`
Describe the bug
I am upgrading this IntelliJ plugin to use the latest version of the gradle-intellij-plugin. Previously, it was using v1.8.1
. As part of the plugin tests, I configured Jacoco to verify that the plugin line coverage was minimum 87%.
After changing the version of gradle-intellij to 1.13.3
, the coverage dropped to 0, but I saw that there was a fix for it in the IntelliJ docs by modifying the test
task. After applying those modifications, the coverage went up to 82%, but I still consistently see these errors being printed on the console when I'm trying to run the test coverage report:
> Task :jacocoTestCoverageVerification FAILED
[ant:jacocoReport] Classes in bundle 'IntelliJ AutoHotkey Plugin' do not match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkNormalLabelStmtImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkHotkeyImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkHotstringStmtImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkNormalLabelImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkHotkeyStmtImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkDirectiveImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkOtherStmtImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkLineImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkHotstringImpl does not match.
[ant:jacocoReport] Execution data for class de/nordgedanken/auto_hotkey/lang/psi/impl/AhkDirectiveStmtImpl does not match.
All the above files are generated by grammar-kit as part of the plugin, so it's not clear why the newer version of the gradle-intellij-plugin is causing this to happen when the old version did not trigger these errors. I'm not sure if there's some setting to toggle (like with the prior fix) to make these go away?
I've tried poking at it for a while but I can't figure out how to resolve these errors so that my coverage goes back to how it was before.
To Reproduce
- Clone https://github.com/Nordgedanken/intellij-autohotkey
- Execute
./gradlew jacocoTestCoverageVerification
to verify that the line coverage is >= 87% (if you see an error about branch coverage, that can be ignored. The important thing is that you won't see the error I pasted above about[ant:jacocoReport] Classes in bundle 'IntelliJ AutoHotkey Plugin' do not match with execution data
) - On line 12, change
version "1.8.+"
toversion "1.13.3"
- Add the following on line 133 within the test task.
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
- Rerun
./gradlew jacocoTestCoverageVerification
- Now you should see the error trace that I pasted above along with the coverage only showing 83% because the classes listed within the error trace above have 0 line coverage
Expected behavior Jacoco should be showing > 0% line coverage for the classes in the error trace above like it was doing with the gradle-intellij-plugin v1.8
Environment:
- OS: Windows 11
- Gradle IntelliJ Plugin Version: 1.13.3
- Gradle Version: 7.4.2
I encountered the same problem. When I upgraded from 1.13.2 to 1.13.3, I noticed that some classes had 0% line coverage and a message stating that the execution data for those classes did not match.
Fortunately, the documentation on the fix has been updated. I followed the steps below and the errors disappeared:
test {
jacoco {
includeNoLocationClasses = true
excludes = ["jdk.internal.*"]
}
}
jacocoTestReport {
classDirectories.setFrom(instrumentCode)
}
jacocoTestCoverageVerification {
classDirectories.setFrom(instrumentCode)
}