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

Remove afterEvaluate wrapper #4159

Merged
merged 2 commits into from
Oct 16, 2021
Merged

Remove afterEvaluate wrapper #4159

merged 2 commits into from
Oct 16, 2021

Conversation

3flex
Copy link
Member

@3flex 3flex commented Oct 4, 2021

Removes usage of afterEvaluate in the Gradle plugin.

This causes race conditions (evidenced by the double use of afterEvaluate in DetektMultiplatform class) and makes it more difficult for users to customise individual tasks created by the plugin.

Generally afterEvaluate shouldn't be required when Gradle's lazy configuration and task configuration avoidance APIs are used. The only tests that failed when I removed it is the multiplatform Android tests, but switching to reactive DomainObjectContainer#all instead of DomainObjectContainer#forEach fixes that.

If there are other use cases that require using afterEvaluate I'll investigate, and if the test coverage didn't pick up issues that removal will now cause, please let me know so I can address it.

Would fix root issue raised in #3428

3flex added 2 commits October 4, 2021 22:10
DomainObjectContainer#all is reactive and applies configuration not just to
objects currently in the collection, but any objects subsequently added to
the collection. `forEach` only applies to objects currently in the
collection, but not any new items subsequently added.
@3flex 3flex added gradle-plugin notable changes Marker for notable changes in the changelog labels Oct 4, 2021
@3flex 3flex requested a review from cortinico October 4, 2021 11:30
@codecov
Copy link

codecov bot commented Oct 4, 2021

Codecov Report

Merging #4159 (e49cc5f) into main (8894bc2) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #4159   +/-   ##
=========================================
  Coverage     83.44%   83.44%           
  Complexity     3177     3177           
=========================================
  Files           465      465           
  Lines          9104     9104           
  Branches       1775     1775           
=========================================
  Hits           7597     7597           
  Misses          572      572           
  Partials        935      935           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8894bc2...e49cc5f. Read the comment docs.

Comment on lines +27 to +28
project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets.all { target ->
target.compilations.all { compilation ->
Copy link
Member

Choose a reason for hiding this comment

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

Could you help verify that we are not breaking the behavior on KMM? I had a discussion on #4026 that if I remember correctly, @cortinico mentioned that it does not work without afterEvaluate.

Copy link
Member Author

Choose a reason for hiding this comment

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

It might have been the use of forEach as mentioned in one of the commits, which did have a failing test until it was fixed.

I asked for cortinico's review already though as I'm aware he's done a lot of work on this part of the plugin and might have suggestions for extra test cases.

Copy link
Member

Choose a reason for hiding this comment

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

Good call on the target.compilations.forEach() -> targe.compilations.all()

Copy link
Member

Choose a reason for hiding this comment

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

Sorry folks for being late to the discussion (I was vactioning 🌴). I think that's a great change @3flex 👍 Thanks for looking into it. I could not fully understand what was causing it. Glad to see that the .forEach was the root cause.

@chao2zhang chao2zhang added this to the 1.19.0 milestone Oct 13, 2021
Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Amazing stuff!

Comment on lines +27 to +28
project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets.all { target ->
target.compilations.all { compilation ->
Copy link
Member

Choose a reason for hiding this comment

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

Sorry folks for being late to the discussion (I was vactioning 🌴). I think that's a great change @3flex 👍 Thanks for looking into it. I could not fully understand what was causing it. Glad to see that the .forEach was the root cause.

@BraisGabin BraisGabin merged commit 44b7660 into detekt:main Oct 16, 2021
@3flex 3flex deleted the afterevaluate branch October 16, 2021 20:16
BraisGabin added a commit that referenced this pull request Nov 11, 2021
BraisGabin added a commit that referenced this pull request Nov 12, 2021
@3flex 3flex restored the afterevaluate branch November 14, 2021 07:06
@3flex 3flex deleted the afterevaluate branch November 15, 2021 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradle-plugin notable changes Marker for notable changes in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants