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

Only add hamcrest-junit dependency when using assertThat or assumeThat #577

Merged
merged 8 commits into from
Aug 17, 2024

Conversation

FieteO
Copy link
Contributor

@FieteO FieteO commented Aug 14, 2024

What's changed?

Remove the hamcrest-junit dependency when running the JUnit4to5Migration recipe.

What's your motivation?

The dependency is not needed in the Junit 5 context (AFAIK)

@timtebeek
Copy link
Contributor

How does this interact with this recipe a little further up/down? As we seem to add that explicitly in a JUnit 5 upgrade

- org.openrewrite.java.testing.hamcrest.AddHamcrestIfUsed

- org.openrewrite.java.dependencies.AddDependency:
groupId: org.hamcrest
artifactId: hamcrest-junit
version: 2.x
scope: test
onlyIfUsing: org.junit.Assume
acceptTransitive: true

What makes that the dependency is not or no longer needed in your case?

@FieteO
Copy link
Contributor Author

FieteO commented Aug 14, 2024

Hmm, you are right. Probably some more investigation is needed as to when the dependency is needed/when it can be removed.
The hamcrest-junit seems to have been the result of decoupling the Hamcrest portions in Junit 4 into a separate dependency.
This dependency hasn't received an update since 9 years and it's hard to say what use it serves. The PR that added it to the junit5.yml was titled Migrate JUnit 4 Assume#assumeThat()tohamcrest-junit`` to fix issue #327 .

As far as I can tell, Junit 5 also has support for Assumptions.
Maybe @knutwannheden can comment on this?

@timtebeek timtebeek marked this pull request as draft August 14, 2024 17:45
@timtebeek timtebeek changed the title Remove hamcrest-junit dependency when migrating from JUnit 4 to 5 Only add hamcrest-junit dependency when using assertThat or assumeThat Aug 17, 2024
@timtebeek timtebeek added the bug Something isn't working label Aug 17, 2024
@timtebeek timtebeek self-requested a review August 17, 2024 11:25
@timtebeek timtebeek marked this pull request as ready for review August 17, 2024 11:25
@timtebeek
Copy link
Contributor

This was a fun one @FieteO ; thanks for raising this for visibility. Turns out we were a little too eager adding that hamcrest-junit dependency on any use of org.junit.Assume, as opposed to only when using assertThat or assumeThat. Solved now by creating a new scanning recipe that looks at methods in use and only if found adds the dependency.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Ended up removing the declarative AddDependency that was there before, and implementing a scanning recipe that's a little more selective. Thanks again for calling out this issue with over eager dependency addition!

@timtebeek timtebeek merged commit b885d12 into openrewrite:main Aug 17, 2024
2 checks passed
@FieteO
Copy link
Contributor Author

FieteO commented Aug 18, 2024

Great, that there indeed was something to improve here. Thanks @timtebeek for working on this.

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
Archived in project
Development

Successfully merging this pull request may close these issues.

Remove hamcrest-junit dependency in Junit4to5Migration recipe
2 participants