What is an "optional" dependency as distinguished from a required package dependency? Why might one add a particular package to a project as optional?

Viewed 133

One could describe a software dependency as being some code or library that is used in a particular package or project which without the required dependency, one would not be able to package the project as a fully functioning program. An 'optional dependency' sounds to a novice software engineer like a contradiction -- e.g. that a project is both dependent on a particular package, but the dependency is also optional and not strictly required.

1 Answers

Optional dependencies are not optional for your project, but when another project depends on your project, these now transitive dependencies are ignored/not resolved. You would do this for features that are not always needed, and to lessen the burden on upstream projects https://blog.gradle.org/optional-dependencies

This is different from a "provided" scope where the dependency is always required, but its up to the environment to make it available. The dependency is not deployed / is not required in your distribution.

Related