question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unwanted tasks added as dependencies to JaCoCo task

See original GitHub issue

In our project (using JUnit 4) we define a jacocoTestReport Gradle task:

task jacocoTestReport(type: JacocoReport, dependsOn: ["testInternalDebugUnitTest"]) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports"
    reports {
        xml.enabled = true
        html.enabled = true
        xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
    }

    sourceDirectories.from = files([mainSrc])
    classDirectories.from = files([debugTree], [kotlinClasses])
    executionData.from = fileTree(dir: "$buildDir", includes: ["**/**/*.exec", "**/**/*.ec"])
}

And when using JUnit 4 and checking the dependency graph we see it is indeed dependent on testInternalDebugUnitTest:

:app:jacocoTestReport
\--- :app:testInternalDebugUnitTest ...

BTW, we have two flavors, Internal and Production.

When I add the JUnit 5 plugin, however, the task is now dependent on all flavors of jacocoTestReport, which are dependent on their respective flavor of unit test task:

:app:jacocoTestReport
+--- :app:jacocoTestReportInternalDebug
|    \--- :app:testInternalDebugUnitTest ...
+--- :app:jacocoTestReportInternalRelease
|    \--- :app:testInternalReleaseUnitTest ...
+--- :app:jacocoTestReportProductionDebug
|    \--- :app:testProductionDebugUnitTest ...
+--- :app:jacocoTestReportProductionRelease
|    \--- :app:testProductionReleaseUnitTest ...
\--- :app:testInternalDebugUnitTest *

Which results in our unit tests running once for each flavor combination, when we only want to run them for InternalDebug.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mannodermauscommented, Jun 26, 2022

I’m glad it turned out well for you in the end! Closing this ticket. 🙏

Is there any side effects of the configuration below?

The only side effect is that the variant-specific Jacoco tasks aren’t generated automatically - other than that, nothing else comes to mind. That being said, this integration with Jacoco stems from a very old requirement, before there was native support for JUnit 5 in Gradle. Now that the first-party tasks run it well, it might be time to deprecate the integration slowly…

0reactions
mannodermauscommented, Oct 22, 2022

Glad to hear that it worked out eventually, and thanks @nuhkoca for chiming in, much appreciated! As for questions related to JUnit 5 execution performance on CI, please raise potential questions on their repo directly 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

The JaCoCo Plugin - Gradle User Manual
Define dependencies between code coverage reports and test execution ... The JaCoCo plugin adds a JacocoTaskExtension extension to all tasks of type Test....
Read more >
gradle - Report is not getting added as part of build phase
Added JACOCO HTML report in my Gradle build for java project. But Report was not getting added as part of build phase, need...
Read more >
JaCoCo - Change History
Branches added by the Kotlin compiler for open functions with default arguments ... added in version 0.6.1 into jacocoant.jar that contains all dependencies...
Read more >
Android+Kotlin Code coverage with Jacoco, Sonar and Gradle ...
Firstly, you will want to add Jacoco plugin to your project. ... from dependencies (for instance by not depending on the task and...
Read more >
Separate Gradle Tasks for Unit and Integration Tests - Inspeerity
Most developers know how painful is accidental, unnecessary run of tests using the ... We need to add dependencies to our integration tests...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found