1

I am trying to add test coverage verification in my kotlin gradle project. I added a super high minimum value (0.99) to fail my build but this task is not getting executed.

tasks.jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        minimum = "0.99".toBigDecimal()
      }
    }
  }
}

The test coverage report is generated successfully from the coverageReport task (details not in the post)

tasks.withType<Test> {
  finalizedBy(coverageReport) // report is always generated after tests run
}

According to jacoco violation rules official documentation

Any violation of the declared rules would automatically result in a failed build when executing the check task.

So I am under the assumption that the test coverage verification should be auto triggered?

So I expected that the jacocoTestCoverageVerification would execute without I having to call it. I also added the following to the jacocoTestCoverageVerification task but still doesn't fail so not writing all the rules is not a likely issue.

rule {
            isEnabled = true
            element = "CLASS"
            includes = listOf("org.gradle.*")

            limit {
                counter = "LINE"
                value = "TOTALCOUNT"
                maximum = "0.99".toBigDecimal()
            }
        }

I also tried :

tasks.jacocoTestCoverageVerification {
  violationRules {
    rule {
      classDirectories.setFrom(sourceSets.main.get().output.asFileTree.matching {
      })
      isEnabled = true
      limit {
        minimum = "0.99".toBigDecimal()
      }
    }
  }
}

Can anyone please help me catch what I am missing?

EDIT:

Gradle version

bin/gradle --version

------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------

Kotlin:       1.7.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.5 (Eclipse Adoptium 17.0.5+8)
OS:           Mac OS X 13.2 aarch64

The gradle build command:

bin/gradle build 

Build logs

Execution optimizations have been disabled for task ':codeCoverageReport' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/Users/Development/myrepo/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml'. Reason: Task ':validateDependenciesKtFile' uses this output of task ':codeCoverageReport' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.6/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '/Users/Development/myrepo/build/reports/jacoco/codeCoverageReport/html'. Reason: Task ':validateDependenciesKtFile' uses this output of task ':codeCoverageReport' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.6/userguide/validation_problems.html#implicit_dependency for more details about this problem.

These indicate that the optimizations are disabled so doesnt seem like a red flag?

A_G
  • 2,260
  • 3
  • 23
  • 56
  • What command are you using to run Gradle? What tasks does Gradle say are running in the log output? Are there any interesting messages in the log output? – aSemy Feb 12 '23 at 21:30
  • Please also include jacaco and gradle versions being used – djmonki Feb 13 '23 at 08:10
  • Updated the post to add gradle version & command @aSemy Nothing much interesting. `buildSrc:check UP-TO-DATE` - this looks good. There is one more, let me add it in the EDIT – A_G Feb 13 '23 at 18:15
  • This will match nothing: `classDirectories.setFrom(sourceSets.main.get().output.asFileTree.matching {})`. This will probably not match your classes: `includes = listOf("org.gradle.*")`. Try running the verification without any includes/exclusions. You could also try `./gradlew clean codeCoverageReport --debug` - what does it say? (This will output a _lot_ of logs, so only focus on the logs relating to the `codeCoverageReport` task) – aSemy Feb 14 '23 at 08:50
  • do you using aussi the plugin: jacocoLogTestCoverage? If yes add: jacocoLogTestCoverage{ finalizedBy jacocoTestCoverageVerification } – Alvaro C. Aug 22 '23 at 00:21

0 Answers0