Can you somehow make a dependency optional? (For a...
# gradle
j
Can you somehow make a dependency optional? (For a library) So that you may have some features in your library, but you can only use them when including a dependency. (and this dependency is also not included in your builds if you haven't got it yourself)
b
Maven has "~provided~optional" deps for that, not sure what gradle's alternative is named
e
compileOnly
is the equivalent, but it would be safer to provide variants in Gradle instead
v
Actually in Maven it would be "optional", not "provided". "provided" is for dependencies you really have to provide to use the library, "optional" is for dependencies that are only needed for specific functionality. Both have the same effect of just being a documentation in the POM and not having any effect on dependency resolution, not even the version is considered. But yeah, as @ephemient said, the poor-man's solution is to use
compileOnly
, the better way is to use proper feature variants, as then at least in Gradle consumers you can properly depend on feature variants and get automatically the dependencies you need. Here is a Gradle Blog entry about that topic: https://blog.gradle.org/optional-dependencies
j
thanks!
103 Views