How to shade a transitive dependency in Gradle?
Yes, you can use the shadow plugin for Gradle to which has a very similar syntax to your example:
// Configuring Filtering for RelocationshadowJar { relocate('junit.textui', 'a') { exclude 'junit.textui.TestRunner' } relocate('junit.framework', 'b') { include 'junit.framework.Test*' }}
Apologies if I've misunderstood your situation and it is in fact more complex but it looks like the exclusion can just be provided in the dependency declaration?
dependencies { ... compile('org.apache.hadoop:hadoop-aws:2.7.1') { exclude group: 'com.amazonaws', module: 'aws-java-sdk' } ...}
You can try the resolutionStrategy
(https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html) to force a particular version.
Example from a projet:
configurations { testImplementation.extendsFrom compileOnly all { resolutionStrategy { // Force jackson 2.4.4 for Spark force 'com.fasterxml.jackson.core:jackson-core:2.4.4', 'com.fasterxml.jackson.core:jackson-databind:2.4.4', 'com.fasterxml.jackson.core:jackson-annotations:2.4.4' force 'com.google.guava:guava:23.6-jre' } }}