8

I have a project which has the apache-compress library as a compile time dependency. This library appears to use Maven and has a POM file with a dependency set up as "optional". Here is the relevant section of the POM file:

<dependency>
  <groupId>org.tukaani</groupId>
  <artifactId>xz</artifactId>
  <version>1.5</version>
  <optional>true</optional>
</dependency>

Gradle does not seem to include this library in to my project, I'm guessing it is because of the "optional" attribute. Is there some way to tell Gradle to include this dependency without explicitly including the xz library myself?

Here is my Gradle dependency declaration: compile group: 'org.apache.commons', name:'commons-compress', version:'1.8.1'

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
jjathman
  • 12,536
  • 8
  • 29
  • 33
  • 1
    Using this same dependency with Ivy it seems that Ivy does include optional dependencies by default, or possibly just ignores that setting completely. – jjathman Oct 06 '14 at 15:59

1 Answers1

11

Optional dependencies aren't considered for transitive dependency resolution, and have to be added explicitly if necessary. (It's the same in Maven.)

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • 2
    Thanks for the definitive answer. Is there a way to tell gradle to include the version of the xz library that is defined in the commons-compress POM instead of explicitly defining some version? – jjathman Oct 06 '14 at 16:04
  • 7
    No there isn't (although I can see this being useful). – Peter Niederwieser Oct 06 '14 at 16:05