Junior — Middle
How do you resolve dependency conflicts when using spring-boot-starter-test?
sobes.tech AI
Answer from AI
Dependency conflicts when using spring-boot-starter-test often occur due to incompatible versions of libraries that are pulled transitively. To resolve them, you can:
- Explicitly specify the versions of conflicting dependencies in
pom.xmlorbuild.gradleusing<dependencyManagement>ordependencyConstraints. - Exclude unwanted transitive dependencies via
<exclusions>in Maven orexcludein Gradle. - Use the command
mvn dependency:treeorgradle dependenciesto analyze the dependency tree and identify conflicts.
Example of excluding a dependency in Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
This way, you can control versions and exclude conflicting libraries.