Is it possible to enforce failOnVersionConflict()
not for the entire configuration, but for only certain group dependency(by name or by group).
Running into this issue as well. Any ideas?
There is no built-in support for that, but with an afterResolve
hook on a configuration, it is possible to achieve it in a custom way:
plugins {
`java-library`
}
repositories {
jcenter()
}
dependencies {
// Creating conflct on animal-sniffer
implementation("com.google.guava:guava:27.0.1-jre")
implementation("org.codehaus.mojo:animal-sniffer-annotations:1.16")
// Creating conflict on hamcrest
testImplementation("org.hamcrest:hamcrest-core:1.2")
testImplementation("junit:junit:4.12")
}
configurations {
testCompileClasspath.get().incoming.afterResolve {
resolutionResult.allComponents {
if (selectionReason.isConflictResolution && moduleVersion != null) {
if (moduleVersion!!.name.contains("hamcrest")) {
throw AssertionError("Cannot have a conflict on hamcrest")
}
}
}
}
}
I’m trying to do this with a Spring Boot app(2.2.4.RELEASE)-
Is there any way to do a similar thing that takes into account Spring Boot’s BOM?
I want to make sure the build doesn’t override anything from the spring bom.
That is a different use case.
Have a look at the documentation for using native support of BOMs in Gradle and enforced platforms as in the example in that linked section.