Gradle Does Not Include Optional Dependency
Asked Answered
W

1

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'

Wrest answered 6/10, 2014 at 15:39 Comment(1)
Using this same dependency with Ivy it seems that Ivy does include optional dependencies by default, or possibly just ignores that setting completely.Wrest
I
11

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

Imputation answered 6/10, 2014 at 16:3 Comment(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?Wrest
No there isn't (although I can see this being useful).Imputation

© 2022 - 2024 — McMap. All rights reserved.