Reputation: 16262
Concrete Example:
I'm writing a library to provide a given functionality. When writing my library, rather than reinventing the wheel, I want to use Apache Commons (ie, StringUtils, etc). Unfortunately, if I include that library with mine, either as a separate jar or built into my own jar (build-with-dependencies), I force Apache Commons on anyone that uses my library... plus I force the version that I used on them.
Question:
Is there a way to create a library/jar in Java that depends on a 3rd party library without forcing that library (or worse, version of that library) on those who use your library?
Upvotes: 3
Views: 147
Reputation: 32407
If you intend to distribute a binary jar via Maven, you shouldn't worry too much about 'forcing' a dependency on anyone who uses the jar. Anyone who uses Maven is completely used to transitive dependencies being dragged in. Maven has lots of whizzy code for sorting out versioning conflicts too.
If you are ultra-paranoid about this, you can use the shade plugin to create an uber-jar with the dependencies and rename all the dependencies' packages: http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html but it's not really necessary.
Upvotes: 1