no
02/20/2025, 11:13 AM@Before
annotation had no effect (it's part of junit4).
Is there a systematic way of preventing junit4 classes from creeping in to my junit5 project? And also vice versa?Vampire
02/20/2025, 11:35 AMno
02/20/2025, 12:10 PMThomas Broyer
02/20/2025, 1:55 PMreject
the "other JUnit"?
(that way, you know where the dependency comes from and you can exclude()
it from that specific dependency's transitives; you could also exclude the dependency at the configuration level but then no longer know where the dependency came from and whether maybe it could be needed, if only at runtime)Adam
02/20/2025, 2:32 PMThomas Broyer
02/20/2025, 3:47 PMimplementation
, and add Truth again as runtimeOnly
without the exclusion (if I use Truth's Assume
):
// This is in a testing suite dependencies {} block
implementation(libs.google.truth) {
exclude(group = "junit", module = "junit")
}
runtimeOnly(libs.google.truth) // bring junit:junit back
Ideally Truth would declare junit:junit as a runtimeOnly dependency, as it's not apparent anywhere in Truth's API, but it's built with Maven so…Adam
02/20/2025, 4:45 PMIdeally Truth would declare junit:junit as a runtimeOnly dependencySounds like another request :) I believe the plugin could modify Truth to make that so
Thomas Broyer
02/20/2025, 5:03 PMAdam
02/20/2025, 5:08 PM@Before
Thomas Broyer
02/20/2025, 5:42 PMexclude
and duplicate `implementation`/`runtimeOnly` declaration with the following in my convention plugin:
jvmDependencyConflicts {
patch {
module("com.google.truth:truth") {
reduceToRuntimeOnlyDependency("junit:junit")
}
}
}
I don't have many dependencies on the projects where I use this, so I didn't put anything in place to possibly fail the build if JUnit 4 somehow appears in the tests' compile classpath.Vampire
02/20/2025, 5:53 PMUse dependency constraints or component selection rules toAh, yeah, better than check task of course. Use a component metadata rule to make Jupiter API and JUnit 4 have one capability in common, so that resolution fails if both end up in the same resolved configuration automatically. You can either do it manually or with the helpers from thethe "other JUnit"?reject
jvm-dependency-conflict-resolution
plugin.
sounds like a good feature request for https://github.com/gradlex-org/jvm-dependency-conflict-resolutionDefinitely not, as there is no conflict. Both can be used at the same time in the same source set just fine as already mentioned, and that is at least for migration but maybe also for other reasons just fine and not a problem at all. It is quite unlikely that a test class is both, a JUnit 4 test as well as a a Jupiter test. But the plugin cannot help you with preventing to use classes from both in the same class or file. And it should definitely not prevent having both in the same classpath by default. Only on request in cases where someone does want to prevent it like @no might want to, and that it already provides as syntax sugar over Gradle API that he could also use directly. 🙂