2
votes

So i have included a local jar as a dependency using following command in gradle -
"compile files("${PathToJar}/name.jar")
Now i want to exclude some module from above jar just like we do with normal dependencies exclusion

compile('com.a.b:' + version) {
        exclude group: 'com.google.inject', module: 'guice_servlet'
        exclude group: 'com.google.inject', module: 'guice'
        exclude group: 'io.dropwizard'
        exclude group: 'org.slf4j'
        exclude group: 'log4j'
    }

I googled a lot but could not find a proper command.

1
I am not following. You want to exclude "module" from a local JAR. How would Gradle know to include transitive dependencies of a local JAR? - Crazyjavahacking
I created a uber jar from my another project and included as a library in my current project. Now from that uber jar, i want to exclude some of the modules.and as far as i know uber jar include all the transitive dependencies, isn't it ? - vaibhav.g

1 Answers

3
votes

What you are trying to achieve is not directly possible in Gradle.

ModuleDependency.exclude(Map) is used for excluding transitive dependencies. That means if dependency depends on another dependency (JAR), Gradle effectively creates dependency tree. By using exclude() method you can remove dependencies from the tree.

However if you have an UberJar, dependencies (classes) are bundled in the JAR itself. So you cannot use exclude() for excluding classes from a JAR itself, it can be only used for excluding JARs from the tree.