Current behaviour with Spring Boot 3.1
When I generate a project from spring initalizr and request that test container support be added I end up with following classpath
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
}
I expected to see something like org.springframework.boot:spring-boot-testcontainers but the presence of org.testcontainers:junit-jupiter is surprising given that junit jupiter is the default for spring boot 3.1, I thought it would automatically be pulled in.
When I examined the dependency tree in my IDE i noticed that org.springframework.boot:spring-boot-testcontainers was pulling in junit 4 which something I don't want in the classpath and the org.springframework.boot:spring-boot-starter-test has exclusions for junit4.
You can find the source code for project where I noticed this behaviour at https://github.com/asaikali/docker-compose-postgres
Suggested Improvements
org.springframework.boot:spring-boot-testcontainersshould addorg.testcontainers:junit-jupiteras a transitive dependencyorg.springframework.boot:spring-boot-testcontainersshould exclude junit4 from its transitive dependencies
I believe implementing the above enhancements makes the dependency handling more consistent with the rest of spring boot's handling of test dependencies.
Comment From: wilkinsona
Thanks for the suggestions.
org.springframework.boot:spring-boot-testcontainers should add org.testcontainers:junit-jupiter as a transitive dependency
spring-boot-starter-test is opinionated about the test framework that we use by default but I am not sure that spring-boot-testcontainers should be. Let's see what the rest of the team thinks.
org.springframework.boot:spring-boot-testcontainersshould exclude junit4 from its transitive dependencies
We can't do that. See https://github.com/testcontainers/testcontainers-java/issues/6934.
Comment From: mhalbritter
org.springframework.boot:spring-boot-testcontainers should add org.testcontainers:junit-jupiter as a transitive dependency
Say I'm only using "Testcontainers at development time", then I don't need the org.testcontainers:junit-jupiter dependency, right? Making it a dependency of org.springframework.boot:spring-boot-testcontainers would pull it in, even when I don't need it.
Comment From: wilkinsona
We discussed this today and agreed that, for the reasons above, we don't want to make the suggested changes. Thanks anyway.
Comment From: asaikali
Thanks for the explanation folks. This makes sense to me now.