Do not ever exclude junit if Testcontainers is used#746
Merged
timtebeek merged 2 commits intoopenrewrite:mainfrom Jun 7, 2025
Merged
Conversation
DidierLoiseau
commented
Jun 7, 2025
|
|
||
| @Test | ||
| void excludeJunit4Dependency() { | ||
| // Just using play-test_2.13 as an example because it appears to still depend on junit. |
Contributor
Author
There was a problem hiding this comment.
I actually wanted to provide a pom with the junit dependency in the test, and then run it as:
rewriteRun(
mavenProject("depends-on-junit", pomXml(remoteDepWithJunit, SourceSpec::skip)),
mavenProject("needs-exclusion", pomXml(before, after)));and somehow it works – the exclusion is added as intended – but it also gets a MavenDownloadException added in the output.
I was trying to do the same as other Maven tests that use SourceSpec::skip, but they all seem to do that for a parent, not a dependency.
timtebeek
approved these changes
Jun 7, 2025
Member
timtebeek
left a comment
There was a problem hiding this comment.
Welcome back! Great use of a precondition indeed for this longer standing wart in our recipes.
Still will keep fingers crossed for a Junit4-less-version-of-testcontainers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
Instead of adding the JUnit 4 exclusion to all dependencies and then removing it from specific ones that depend on Testcontainers, just don’t add the exclusion when Testcontainers is used.
What's your motivation?
We have implemented some test libraries that (transitively) depend on Testcontainers. When (indirectly) running the JUnit 5 migration recipe, it always adds the junit exclusion on those, which breaks the build. This forces us to un-exclude JUnit 4 as a followup recipe.
Have you considered any alternatives or workarounds?
Current workaround is to remove the exclusion explicitly for all dependencies after JUnit 5 migration:
Any additional context
This makes the recipe more conservative. If a project transitively depends on Testcontainers, it won’t add the exclusion to dependencies that do not depend on Testcontainers (but still depend on JUnit 4) but that’s ok since exclusions have to be added everywhere to work properly.
This provides a more generic solution to #429 and #477.
Checklist