Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shade a transitive dependency in Gradle?

Is there a way to shadow a particular (transitive) dependency in Gradle? My situation: I have a project that depends directly on com.amazonaws:aws-java-sdk-emr:1.10.33 and org.apache.hadoop:hadoop-aws:2.7.1, but hadoop-aws in turns depends on com.amazonaws:aws-java-sdk-emr:1.7.4 which screws the final JAR, but I need both anyway.

Is it currently possible to do something like this?

shadowJar {
    relocate('com.amazonaws', 'shadowedstuff.awsjdk') {
        include(dependency('com.amazonaws:aws-java-sdk:1.7.4'))
    }
}

Or a not-so-dirty workaround for it?

Thanks!

NOTE: shading the aws-sdk which my projects depends on directly is not an option. This is a simplification and in the original setup some reflection is going on.

like image 418
ale64bit Avatar asked Dec 17 '15 20:12

ale64bit


1 Answers

Yes, you can use the shadow plugin for Gradle to which has a very similar syntax to your example:

// Configuring Filtering for Relocation
shadowJar {
   relocate('junit.textui', 'a') {
       exclude 'junit.textui.TestRunner'
   }
   relocate('junit.framework', 'b') {
       include 'junit.framework.Test*'
   }
}
like image 183
sschuberth Avatar answered Sep 20 '22 14:09

sschuberth