How to exclude a JAR from distZip?

I am building a command line application. My application depends on jdom-1.1.jar. However from some 3rd party library there is a dependency on jdom-1.0.jar (I dunno from where). When I run ./gradlew distZip I get both JARs in my lib directory (Gradle 2.7). How can I exclude jdom-1.0.jar? I have tried

distributions {
  main {
    baseName = 'mail-director'
    contents {
      from {'src/dist'}
    }
  }
  applicationDistribution.exclude('**/jdom-1.0.jar')
}

but that does not work.

The contents closure of distributions is a CopySpec, so it works just like a CopySpec would.

You should be able to exclude it there.

Alternatively, you can find out which of the dependencies has the transitive dependency by doing:

./gradlew dependencies

Then exclude that transitive dependency from that definition.

dependencies {
    compile 'has:transitive:dependency:1.0' {
        transitive = false
    }
}
1 Like

Thank you. That solved it. I had used ./gradlew dependencies a while back, but had forgotten how it worked.