RFR: Add build support for generating Jacoco coverage reports [v2]
Jorn Vernee
jvernee at openjdk.org
Mon Dec 4 22:13:03 UTC 2023
On Mon, 4 Dec 2023 22:06:16 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> Add a new `coverage` gradle task that can be used to generate a Jacoco test coverage report. Because we're on the bleeding edge, the user running the build needs to build Jacoco from source for this to work.
>>
>> As an example: I've cloned Jacoco from here: https://github.com/jacoco/jacoco and built the project using:
>>
>> mvn package -DskipTests -Dbytecode.version=22
>>
>> Then, I point gradle at the generated artifacts using:
>>
>> jacoco_cli=<jacoco repo>/org.jacoco.cli/target/org.jacoco.cli-0.8.12-SNAPSHOT-nodeps.jar
>> jacoco_agent=<jacoco repo>/org.jacoco.agent/target/classes/jacocoagent.jar
>>
>> I've put these in a local `gradle.properties` file instead of passing them on the command line.
>>
>> I then run `./gradlew coverage` which generates an html coverage report under `./build/jacoco-report`.
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
>
> lazily configure coverage task
build.gradle line 232:
> 230: createJtregTask("jtregWithCoverage", true, os_lib_dir)
> 231:
> 232: tasks.register("coverage", JavaExec) {
Note that I'm using `tasks.register` here to make the configuration of this task lazy. That allows us to avoid an error when the `jacoco_cli` is not set, but the task isn't invoked.
The old jtreg task did this in a `doFirst` block, but that code actually doesn't run until the task itself is invoked. So, if there is a missing property, and the configuration references that property, we'll get an NPE instead of the intended exception.
Note that I've moved the property null check out of the `doFirst` block of the jtreg task as well, and made the configuration lazy there too. If I do that, I see an exception as expected when the task is configured, but not when the task doesn't run.
-------------
PR Review Comment: https://git.openjdk.org/jextract/pull/153#discussion_r1414567311
More information about the jextract-dev
mailing list