I’m trying to figure out what would be the correct way to exclude transitive dependency from a specific dependency for all projects. Basically I’m trying to achieve what Spring dependency management plugin does but with Gradle’s dependency constraints: https://docs.spring.io/dependency-management-plugin/docs/current-SNAPSHOT/reference/html/#dependency-management-configuration-dsl-exclusions
So far I figured I can do the following in the root build.gradle.kts
to control the dependency versions:
plugins {
java
}
subprojects {
apply {
plugin("java")
}
repositories {
mavenCentral()
}
dependencies {
constraints {
dependency("some:dependency")
}
}
}
fun DependencyConstraintHandler.dependency(constraintNotation: Any) {
configurations.all {
add(name, constraintNotation)
}
}
I though struggle to find the way to exclude transitive dependency of a specific dependency in a centralized way. I know I can exclude the dependency completely from the configuration
, but that’s too much as sometimes I still need to keep a transitive dependency for one of the dependencies.
Is there a way of doing it without defining the exclude in every module where the dependency is imported?