Lokesh Pandey
Lokesh Pandey

Reputation: 1789

jacoco configuration for multi module is not working

There is something strange going on with my jacoco configuration and I am not able to figure it out. I have visited multiple threads on stack overflow and other platforms and tried many thing, but didn't resolve this issue.

I have setup the java code coverage for multiple modules. This is my project structure

I have configured the jacoco for my DEF maven project. I am only configuring my DEF project. And this is what pom.xml contains

    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.8</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>report-aggregate</goal>
                </goals>
                <configuration>
                 <outputDirectory>${project.basedir}/target/reports</outputDirectory>
                </configuration>
                </execution>
        </executions>
    </plugin>

Issue: The issue here is, it's generating the code coverage report in each module1, module2 and module3. But the report generated in module1, doesn't contains the code coverage for itself. Meaning, it shows the code coverage for module2 and module3, but it doesn't include module1 report in itself. I don't know what's wrong ?

EDIT : modules in DEF are maven modules and it didn't contains anything related to jacoco.

Any idea or any suggestions ?

Thanks

Upvotes: 2

Views: 1770

Answers (3)

duhocsinhlienxo
duhocsinhlienxo

Reputation: 93

You can try to merge unit test and instrument test from app module :

task jacocoUiTestReportAllModules(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
    group "Reports"
    description "Generate Jacoco Instrumented Tests coverage reports for all modules"
    reports {
        xml.enabled = true
        html.enabled = true
        html.destination file("${rootProject.buildDir}/coverage-report")
    }
    def javaClasses = []
    def kotlinClasses = []
    def javaSrc = []
    def kotlinSrc = []
    def execution = []
    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
    rootProject.subprojects.each { proj ->
        javaClasses << fileTree(dir: "$proj.buildDir/intermediates/javac/debug", excludes: fileFilter)
        kotlinClasses << fileTree(dir: "$proj.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
        javaSrc << "$proj.projectDir/src/main/java"
        kotlinSrc << "$proj.projectDir/src/main/kotlin"
        execution << fileTree(dir: proj.buildDir, includes: [    'jacoco/testDebugUnitTest.exec',
                'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])
    }
    getSourceDirectories().setFrom(files([javaSrc, kotlinSrc]))
    getClassDirectories().setFrom(files([javaClasses, kotlinClasses]))
    getExecutionData().setFrom(execution)

    doLast() {
        print "file://${reports.html.destination}/index.html"

    }
}

Upvotes: 0

Lokesh Pandey
Lokesh Pandey

Reputation: 1789

Thank you @Sarang for the response. It did resolve my problem, but after that I ran into one more issue and that is for one of my module it was not generating the jacoco.exec file. After some investigation it seems the problem was with <argLine> tag. In one of my module I was using this tag and somehow this was overridden.

So what I did is I pre append the argLine before this and it resolve my issue

<configuration>
    <argLine>${argLine} -XX:PermSize=256m -XX:MaxPermSize=1048m</argLine>
</configuration>

Upvotes: 3

Sarang
Sarang

Reputation: 512

Create one more module as ReportAggregator and move jacoco configuration from parent pom to ReportAggregator pom

Upvotes: 2

Related Questions