Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using the jacoco report aggregation plugin, some classes are not clickable in the report. #20482

Closed
juanmbellini opened this issue Apr 18, 2022 · 2 comments
Assignees
Milestone

Comments

@juanmbellini
Copy link

juanmbellini commented Apr 18, 2022

Maybe I'm not understanding well something about the jacoco-report-aggregation plugin...

I have a multi module project with the following structure

.
├── buildSrc
│   ├── build.gradle
│   ├── gradle.properties
│   └── src
│       └── main
│           └── groovy
│               ├── java-common-conventions.gradle
│               ├── modules-conventions.gradle
│               └── springboot-application-conventions.gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── modules
│   ├── adapters
│   │   ├── spring-data-persistence-adapter
│   │   ├── spring-security-authentication-adapter
│   │   └── spring-webmvc-service-adapter
│   ├── core
│   │   ├── model
│   │   ├── usecase
│   │   └── utilities
│   ├── main
│   │   ├── build
│   │   ├── build.gradle
│   ├── ports
│   │   ├── authentication-port
│   │   ├── persistence-port
│   │   └── service-port
│   └── resources
│       ├── build
│       ├── build.gradle
└── settings.gradle

In the buildSrc I have some convention plugins. The java-common-conventions plugin is defined as the following:

plugins {
    id 'java'
    id 'jacoco'
    id 'io.spring.dependency-management'
}

repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
        mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
    }
}

group = 'com.github.juanmbellini'
version = '0.0.1-SNAPSHOT'


java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}


compileJava {
    options.encoding = 'UTF-8'
    options.compilerArgs << '-parameters'
}

compileTestJava {
    options.encoding = 'UTF-8'
}

ext {
    jjwtVersion = "0.11.2"
}

dependencies {
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    implementation 'org.apache.commons:commons-lang3'

    testCompileOnly 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

    testImplementation 'org.mockito:mockito-core'
    testImplementation 'org.mockito:mockito-junit-jupiter'
    testImplementation 'org.junit.jupiter:junit-jupiter-api'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}


tasks.named('test') {
    useJUnitPlatform()
}

test {
    finalizedBy jacocoTestReport
}

jacocoTestReport {
    dependsOn test
}

This plugin is used by all subprojects.

Then I have a plugin which is only used by the main subproject - i.e the one defining the main method - called : springboot-application-conventions

plugins {
    id 'java-common-conventions'
    id 'jacoco-report-aggregation'
    id 'org.springframework.boot'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('check') {
    dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
}

This works perfectly well except for the fact that it only generates report pages for java classes (i.e pages where I can see the code with the green and red highlights, the diamonds, etc.) that are in the main module, but classes in all other modules do not have these pages. I can see coverage percentages for each class and method, but I cannot see the code with the coverage data.

Expected Behavior

All classes should be clickable in order to gather coverage data in an aggregated way without having to navigate each project.

Current Behavior

Only classes in the main module (the one with aggregation plugin) are clickable in the report.

Context

Not affecting work right now as I'm learning how to use this plugin.

In my case I was able to partially fix it with the following hack (added to the main subproject build.gradle):

def otherModules = [
        ':modules:resources',
        ':modules:core:model',
        ':modules:core:usecase',
        ':modules:core:utilities',
        ':modules:ports:persistence-port',
        ':modules:ports:authentication-port',
        ':modules:ports:service-port',
        ':modules:adapters:spring-data-persistence-adapter',
        ':modules:adapters:spring-security-authentication-adapter',
        ':modules:adapters:spring-webmvc-service-adapter'
]

otherModules.each {
    evaluationDependsOn it
}

testCodeCoverageReport {
    for (module in otherModules) {
        sourceSets project(module).sourceSets.main
    }
}

The problem with this is that I have to manually add each subproject to the main subproject, which I think it's super error-prone.

Steps to Reproduce

I don't have a public project to be shared right now, but I can prepare one.

Environment

------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------

Build time:   2022-03-31 15:25:29 UTC
Revision:     540473b8118064efcc264694cbcaa4b677f61041

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.2 (Homebrew 17.0.2+0)
OS:           Mac OS X 11.6 x86_64

@DPUkyle
Copy link
Member

DPUkyle commented May 16, 2022

Hi @juanmbellini , unfortunately I was not able to reproduce this.

I set a breakpoint on the last line of one of our integration tests, org.gradle.testing.jacoco.plugins.JacocoAggregationIntegrationTest#can aggregate jacoco execution data from subprojects, then browsed the HTML report myself. I was able to drill-down into the pages of all classes, including both the "main" application project and the subprojects it depends on (including transitively).

Please provide a reproducer project if you are able.

@DPUkyle DPUkyle closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2022
@DPUkyle
Copy link
Member

DPUkyle commented Jul 1, 2022

Unable to reproduce; closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants