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

Rewire Jacoco for Gradle 8/9 #3052

Merged
merged 18 commits into from Jul 8, 2023
Merged

Conversation

TWiStErRob
Copy link
Contributor

@TWiStErRob TWiStErRob commented Jul 4, 2023

Fixes the :jacocoAgent warning listed in #3051, see individual commits to make sense of the "full rewrite". cc @szpak for review because #1229 (comment).

Checklist

  • Read the contributing guide
  • PR should be motivated, i.e. what does it fix, why, and if relevant how
  • If possible / relevant include an example in the description, that could help all readers
    including project members to get a better picture of the change
  • Avoid other runtime dependencies
  • Meaningful commit history ; intention is important please rebase your commit history so that each
    commit is meaningful and help the people that will explore a change in 2 years
  • The pull request follows coding style
  • Mention Fixes #<issue number> in the description if relevant
  • At least one commit should mention Fixes #<issue number> if relevant

The jacoco plugin was applied on the wrong Project object which lead to multiple workarounds:
 * somehow `apply plugin:` binds to the script default project which is rootProject
 * so the plugin wasn't applied to currentProject
 * so it didn't register .jacoco on the Test tasks
 * so manual `applyTo()` was required
 * calling `applyTo test` resolved to `rootProject.jacoco.applyTo(currentProject.tasks.test)` (because the currentProject.jacoco wasn't registered!)
 * which lead to a cross-project configuration leak, and we had the warning:

> Task :*:test
Resolution of the configuration :jacocoAgent was attempted from a context different than the project context. Have a look at the documentation to understand why this is a problem and how it can be resolved. This behavior has been deprecated. This will fail with an error in Gradle 9.0. For more information, please refer to https://docs.gradle.org/8.2/userguide/viewing_debugging_dependencies.html#sub:resolving-unsafe-configuration-resolution-errors in the Gradle documentation.
Because of the manual applyTo() call the project object was always rootProject which set the wrong destinationFile and tasks overwrote each others' outputs. The workaround to manually split these files is no longer necessary after the previous commit.
@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.25 ⚠️

Comparison is base (b2e7541) 85.69% compared to head (b60e1bb) 85.45%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3052      +/-   ##
============================================
- Coverage     85.69%   85.45%   -0.25%     
- Complexity     2874     2888      +14     
============================================
  Files           326      329       +3     
  Lines          8727     8801      +74     
  Branches       1077     1093      +16     
============================================
+ Hits           7479     7521      +42     
- Misses          971      992      +21     
- Partials        277      288      +11     

see 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@szpak
Copy link
Member

szpak commented Jul 5, 2023

cc @szpak for review because #1229 (comment).

Wow. It was long time ago. In those times, I was much more up-to-date with the Gradle development and recommendations for plugin makers :-D.

@TimvdLippe
Copy link
Contributor

Seems like the Android coverage is now working correctly? We do decrease the coverage, but that's because we miss some stuff in Android.

I think this PR is ready now, is it not? Thanks again for taking this on!

@TWiStErRob
Copy link
Contributor Author

Yeah, I think this is ready. It's a bit ugly and hacky with the coverage gathering from android modules and exclusions.

And where I managed to generate coverage for a dependency of the androidTest module. The runtimeOnly vs exclude hack can be simplified if the androidTest is split up into androidInstrumentedTest and androidUnitTest modules.

I like how the codecov-action turned out though, way simpler than all the unix magic before.

The coverage change is all expected: https://app.codecov.io/gh/mockito/mockito/pull/3052/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mockito

It shows that android module is now covered and some of the core mockito classes are also covered more (probably because the coverage files are also aggregated from android module's unit tests). I wouldn't look at it as a decrease, but more as a "more realistic measurement" of the coverage 😅.

If you're ok with the resulted code and tricks, happy to merge this now.

@TimvdLippe
Copy link
Contributor

Yeah very happy that we now have a proper view of test coverage of our Android code. It also shows we are missing a bit there.

I was about to merge this, but then I spotted one last nit: the report includes subprojects/androidTest/src/main/java/org/mockitousage/androidtest/BasicClassesForTesting.kt. I think we need to exclude src/main/java of our androidTest project.

@TimvdLippe
Copy link
Contributor

Also, with regards to cleaning up the instrumentation and unit tests for Android, I would be happy to merge a PR for that if you fancy picking it up.

@TWiStErRob
Copy link
Contributor Author

TWiStErRob commented Jul 8, 2023

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thank you!

@TimvdLippe TimvdLippe merged commit 69e0a6c into mockito:main Jul 8, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants