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

Problem with gradlew jacocoRootMerge with gradle project using kotlin DSL #198

Closed
ursjoss opened this issue Nov 11, 2019 · 10 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ursjoss
Copy link
Contributor

ursjoss commented Nov 11, 2019

If the project is configured using gradle kotlin DSL, the jacoco aggregation tasks

  • jacocoRootMerge
  • jacocoRootReports

fail. Find the Reproducer here.

Note: A quite similarly configured project - albeit using groovy syntax - runs both commands successfully. Reproducer.

  • The jacoco tasks that run on the subprojects directly succeed.
  • I have the impression that - using kotlin DSL - gradle tries to find an existing *.exec file even in the root module (within build\jacoco). Instead it should only try to write the aggregated files into that directory.

It may well be that the problem comes from some misconfiguration on my behalf.

@ursjoss
Copy link
Contributor Author

ursjoss commented Nov 12, 2019

I somewhat simplified the two reproducers and made sure the jacoco config is equivalent. I had missed to base jacoco enabling based on src/test in the kotlin configured reproducer 2.

Unfortunately, the problem persists...

@aalmiray
Copy link
Collaborator

There's indeed a difference in the setup in each project. If you run gradlew :jacocoRootReportTaskSettings (new Rule in 0.30.0-SNAPSHOT ;-) on each project you'll notice that the java/groovy project lists only dependencies on its subprojects while the kotlin project adds a dependency on the root a if it contained test sources. This is what's causes the jacoco tasks to fail.

> Task :jacocoRootMergeTaskSettings
jacocoRootMerge:
    actions:
        org.gradle.api.internal.AbstractTask$TaskActionWrapper@109e737c
    ant: org.gradle.api.internal.project.DefaultAntBuilder@6c048a7a
    antBuilder: org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder@611954a4
    asDynamicObject: DynamicObject for task ':jacocoRootMerge'
    class: class org.gradle.testing.jacoco.tasks.JacocoMerge_Decorated
    convention: org.gradle.api.internal.plugins.DefaultConvention@491e38d6
    conventionMapping: org.gradle.internal.extensibility.ConventionAwareHelper@2a78a71a
    dependsOn:
            task ':project2:integrationTest'
            task ':project2:test'
            task ':project3:functionalTest'
            task ':project3:test'
            task ':project2:jacocoIntegrationTestReport'
            task ':project2:jacocoTestReport'
            task ':project3:jacocoFunctionalTestReport'
            task ':project3:jacocoTestReport'
    description: Aggregate Jacoco coverage reports.
    destinationFile: /private/tmp/kordamp-gradle-test-suite/01_java_gradle_groovy/build/jacoco/root.exec
    destroyables: org.gradle.api.internal.tasks.DefaultTaskDestroyables@62e7af75
    didWork: false
    enabled: true
    executionData:
        /private/tmp/kordamp-gradle-test-suite/01_java_gradle_groovy/subprojects/project2/build/jacoco/integrationTest.exec
        /private/tmp/kordamp-gradle-test-suite/01_java_gradle_groovy/subprojects/project2/build/jacoco/test.exec
        /private/tmp/kordamp-gradle-test-suite/01_java_gradle_groovy/subprojects/project3/build/jacoco/functionalTest.exec
        /private/tmp/kordamp-gradle-test-suite/01_java_gradle_groovy/subprojects/project3/build/jacoco/test.exec
    extensions: org.gradle.api.internal.plugins.DefaultConvention@491e38d6
    group: Reporting
    hasCustomActions: false
    identityPath: :jacocoRootMerge
    impliesSubProjects: false
    inputs: org.gradle.api.internal.tasks.DefaultTaskInputs@1ebf0bc6
    jacocoClasspath:
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.ant/0.8.4/b3e8c1502a20b253c9c361661a329c1fc076197e/org.jacoco.ant-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.report/0.8.4/e5ca9511493b7e3bc2cabdb8ded92e855f3aac32/org.jacoco.report-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.core/0.8.4/53addc878614171ff0fcbc8f78aed12175c22cdb/org.jacoco.core-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.agent/0.8.4/ef23c1c9c84aded1e8dfe24ce3c3f384386b7b59/org.jacoco.agent-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/7.1/431dc677cf5c56660c1c9004870de1ed1ea7ce6c/asm-commons-7.1.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/7.1/379e0250f7a4a42c66c5e94e14d4c4491b3c2ed3/asm-analysis-7.1.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/7.1/a3662cf1c1d592893ffe08727f78db35392fa302/asm-tree-7.1.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/7.1/fa29aa438674ff19d5e1386d2c3527a0267f291e/asm-7.1.jar
    localState: org.gradle.api.internal.tasks.DefaultTaskLocalState@6824971a
    logger: org.gradle.internal.logging.slf4j.DefaultContextAwareTaskLogger@7393cba7
    logging: org.gradle.internal.logging.compatbridge.LoggingManagerInternalCompatibilityBridge@ce45959
    onlyIf: org.gradle.api.specs.AndSpec@d4342096
    outputs: org.gradle.api.internal.tasks.DefaultTaskOutputs@705bd800
    path: :jacocoRootMerge
    project: root project '01_java_gradle_groovy'
    services: ProjectScopeServices
    standardOutputCapture: org.gradle.internal.logging.compatbridge.LoggingManagerInternalCompatibilityBridge@ce45959
    state: org.gradle.api.internal.tasks.TaskStateInternal@3fda76f6
    taskActions:
        org.gradle.api.internal.AbstractTask$TaskActionWrapper@109e737c
    taskDependencies:
        task ':project2:integrationTest'
        task ':project2:test'
        task ':project3:functionalTest'
        task ':project3:test'
        task ':project2:jacocoIntegrationTestReport'
        task ':project2:jacocoTestReport'
        task ':project3:jacocoFunctionalTestReport'
        task ':project3:jacocoTestReport'
    taskIdentity: TaskIdentity{path=:jacocoRootMerge, type=class org.gradle.testing.jacoco.tasks.JacocoMerge, uniqueId=3803}
    temporaryDir: /private/tmp/kordamp-gradle-test-suite/01_java_gradle_groovy/build/tmp/jacocoRootMerge
    temporaryDirFactory: org.gradle.api.internal.AbstractTask$15@24fe05d1

Now for the kotlin DSL project

> Task :jacocoRootMergeTaskSettings
jacocoRootMerge:
    actions:
        org.gradle.api.internal.AbstractTask$TaskActionWrapper@4444c596
        org.gradle.api.internal.AbstractTask$TaskActionWrapper@36384772
    ant: org.gradle.api.internal.project.DefaultAntBuilder@309915f
    antBuilder: org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder@38662a95
    asDynamicObject: DynamicObject for task ':jacocoRootMerge'
    class: class org.gradle.testing.jacoco.tasks.JacocoMerge_Decorated
    convention: org.gradle.api.internal.plugins.DefaultConvention@5aec307a
    conventionMapping: org.gradle.internal.extensibility.ConventionAwareHelper@2e1bff82
    dependsOn:
            task ':test'                       <--- PROBLEM !!
            task ':project2:integrationTest'
            task ':project2:test'
            task ':project3:functionalTest'
            task ':project3:test'
            task ':jacocoTestReport'           <--- PROBLEM !!
            task ':project2:jacocoIntegrationTestReport'
            task ':project2:jacocoTestReport'
            task ':project3:jacocoFunctionalTestReport'
            task ':project3:jacocoTestReport'
    description: Aggregate Jacoco coverage reports.
    destinationFile: /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/build/jacoco/root.exec
    destroyables: org.gradle.api.internal.tasks.DefaultTaskDestroyables@61d71077
    didWork: false
    enabled: true
    executionData:
        /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/build/jacoco/test.exec           <--- PROBLEM !!
        /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/subprojects/project2/build/jacoco/integrationTest.exec
        /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/subprojects/project2/build/jacoco/test.exec
        /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/subprojects/project3/build/jacoco/functionalTest.exec
        /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/subprojects/project3/build/jacoco/test.exec
    extensions: org.gradle.api.internal.plugins.DefaultConvention@5aec307a
    group: Reporting
    hasCustomActions: true
    identityPath: :jacocoRootMerge
    impliesSubProjects: false
    inputs: org.gradle.api.internal.tasks.DefaultTaskInputs@222e3cd7
    jacocoClasspath:
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.ant/0.8.4/b3e8c1502a20b253c9c361661a329c1fc076197e/org.jacoco.ant-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.report/0.8.4/e5ca9511493b7e3bc2cabdb8ded92e855f3aac32/org.jacoco.report-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.core/0.8.4/53addc878614171ff0fcbc8f78aed12175c22cdb/org.jacoco.core-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.agent/0.8.4/ef23c1c9c84aded1e8dfe24ce3c3f384386b7b59/org.jacoco.agent-0.8.4.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/7.1/431dc677cf5c56660c1c9004870de1ed1ea7ce6c/asm-commons-7.1.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/7.1/379e0250f7a4a42c66c5e94e14d4c4491b3c2ed3/asm-analysis-7.1.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/7.1/a3662cf1c1d592893ffe08727f78db35392fa302/asm-tree-7.1.jar
        /Users/aalmiray/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/7.1/fa29aa438674ff19d5e1386d2c3527a0267f291e/asm-7.1.jar
    localState: org.gradle.api.internal.tasks.DefaultTaskLocalState@7e978f5
    logger: org.gradle.internal.logging.slf4j.DefaultContextAwareTaskLogger@2097f6f7
    logging: org.gradle.internal.logging.compatbridge.LoggingManagerInternalCompatibilityBridge@4ea10837
    onlyIf: org.gradle.api.specs.AndSpec@a7a1d00a
    outputs: org.gradle.api.internal.tasks.DefaultTaskOutputs@746f5d49
    path: :jacocoRootMerge
    project: root project '02_java_gradle_kotlin_dsl'
    services: ProjectScopeServices
    standardOutputCapture: org.gradle.internal.logging.compatbridge.LoggingManagerInternalCompatibilityBridge@4ea10837
    state: org.gradle.api.internal.tasks.TaskStateInternal@55294e70
    taskActions:
        org.gradle.api.internal.AbstractTask$TaskActionWrapper@4444c596
        org.gradle.api.internal.AbstractTask$TaskActionWrapper@36384772
    taskDependencies:
        task ':test'                       <--- PROBLEM !!
        task ':project2:integrationTest'
        task ':project2:test'
        task ':project3:functionalTest'
        task ':project3:test'
        task ':jacocoTestReport'           <--- PROBLEM !!
        task ':project2:jacocoIntegrationTestReport'
        task ':project2:jacocoTestReport'
        task ':project3:jacocoFunctionalTestReport'
        task ':project3:jacocoTestReport'
    taskIdentity: TaskIdentity{path=:jacocoRootMerge, type=class org.gradle.testing.jacoco.tasks.JacocoMerge, uniqueId=4170}
    temporaryDir: /private/tmp/kordamp-gradle-test-suite/02_java_gradle_kotlin_dsl/build/tmp/jacocoRootMerge
    temporaryDirFactory: org.gradle.api.internal.AbstractTask$15@168ea304

@aalmiray
Copy link
Collaborator

Apparently the difference stems in that the root project in 02_java_gradle_kotlin_dsl applies the java plugin to itself while 01_java_gradle_groovy does not. This change causes the jacoco plugin to configure the project such that it's expected of it to generate test data, but of course it does not as the root is not a real Java project.

@ursjoss
Copy link
Contributor Author

ursjoss commented Nov 12, 2019

@aalmiray Thank a lot for the analysis (that's a very handy plugin that will reach us in 0.30.0 :-) ).

I will apply your findings to my reproducer and the actual repo where I stumbled into this issue and will update asap (probably this evening).

Thanks a lot so far...

@aalmiray
Copy link
Collaborator

Perhaps there's a way to set a root project to have some Java conventions but not all. Wonder it that makes sense at all.

@ursjoss
Copy link
Contributor Author

ursjoss commented Nov 12, 2019

You're of course right, it was the java plugin applied in the plugins section of the root build.gradle file.

It's not so trivial to avoid the problem using kotlin dsl though. It's the java plugin that provides the accessor functions such as testImplementation I use in the subproject section.

See gradle/kotlin-dsl-samples#916.

I managed to get it working, but it's not as clean as I'd like it to have (I had to apply the java plugin in the submodule gradle files to get access to the accessors in those configuration files. It would be much easier to just be able to apply the java plugin as I initially did.

It would be very convenient if the kordamp project plugin was able to prevent the application of the jacocoRootMerge/Report plugins to the project root. But I'm not even sure if this would apply to all scenarios or even makes sense. What do you think?

@aalmiray
Copy link
Collaborator

Well as it turns out jacocoRootMerge/jacocoRootReport ought to be applied to the root only. The problem is that the kordamp jacoco plugin "believes" that any project with the java-base plugin applied to it should be included in the jacoco aggregation. A workaround is to set jacoco.enabled = false but this only works on a subdir. If that property is set on the root the the root jacoco reports are completely skipped.

Perhaps the root can have java-base/java applied to it but also check if it actually has any test source sets.

@ursjoss
Copy link
Contributor Author

ursjoss commented Nov 12, 2019

That latter suggestion simply leads to the jacocoRootMerge or jacocoRootReport being skipped entirely.

@ursjoss
Copy link
Contributor Author

ursjoss commented Nov 12, 2019

I updated the reproducer with that suggestion (and also reverted it).

@aalmiray aalmiray self-assigned this Nov 12, 2019
@aalmiray aalmiray added the bug Something isn't working label Nov 12, 2019
@aalmiray aalmiray added this to the 0.30.0 milestone Nov 12, 2019
@ursjoss
Copy link
Contributor Author

ursjoss commented Nov 12, 2019

Hey, very neat. Thanks a lot for the quick resolution :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants