, is there a way to exclude a dependency from the test compile classpath?
Context - I’m migrating a project from JUnit 4 to JUnit 5. But it uses testcontainers, which has a transitive dependency on JUnit 4. It’s really easy to accidentally use JUnit 4 annotations, and then find your tests aren’t running… I’d like to exclude JUnit 4 from the test compile classpath so that if you do so you find out fast.
Maven doesn’t distinguish between compile & runtime for test scope (why not?!) so I can’t just drop it down to be a runtime scoped dependency.
I could exclude it as a dependency of testcontainers, but:
a) that would exclude it from the runtime classpath, and testcontainers probably needs it
b) the odds are some other dependency will bring it in, now or later… playing whack-a-mole like that is zero fun
(Yes it would be easy in Gradle. No I’m not up for having that fight now.)
😶 1
h
hho
07/21/2021, 10:06 AM
Why would testcontainers need it at runtime, if you don't want to run JUnit 4 stuff? I'd try excluding it… 🤷♂️
r
Rob Elliot
07/21/2021, 10:08 AM
GenericContainer
implements
org.junit.rules.TestRule
. I’m fairly sure the JVM will fail trying to load a class where some of the supertypes are not on the runtime classpath.
😟 1
h
hho
07/21/2021, 10:11 AM
OK, if it's so tightly coupled, I guess the problem is testcontainers – not Maven.
r
Rob Elliot
07/21/2021, 10:12 AM
It’s both. If maven allowed distinguishing between the compile & runtime classpath for tests then I could make JUnit 4 runtime scoped, which would stop anyone accidentally compiling against JUnit 4.
Rob Elliot
07/21/2021, 10:26 AM
It’s a question about the
kotlin-maven-plugin
, in the hope that the
kotlin-maven-plugin
has a way to modify the compile time classpath. In what possible way is that
NOT KOTLIN
?
h
hho
07/21/2021, 11:45 AM
Maven assembles the classpaths, nothing Kotlin specific here.
r
Rob Elliot
07/21/2021, 11:49 AM
I know that. I was asking about a possible backdoor in the