Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of dependency-reduced-pom.xml generated by the shade plugin?

I read over the docs and didn't find anything that talks about what it's used for.

like image 854
Transcendence Avatar asked Apr 07 '14 05:04

Transcendence


People also ask

What is the purpose of the Maven shade plugin?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

What is a dependency POM xml?

POM is an acronym for Project Object Model. The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc. Maven reads the pom.

What happens when we add dependency in POM xml?

Maven will download the new dependencie(s) to your local repository and then use this to compile your JAR. If you are packaging your application as a web archive (WAR file), it would include the binaries of the dependency (and any binaries it depends on) in your WAR file. Save this answer.

What does shaded mean in Maven?

Together literally it means "jar-over-all-other-jars". "Shading" is the same as "package reallocation" which is needed for classes or resources that collide. – dma_k.


2 Answers

The shade:shade Mojo is quite well documented, here especially about the createDependencyReducedPom parameter, which will create that dependency-reduced-pom.xml file: maven-shade-plugin/shade-mojo.html#createDependencyReducedPom

In short, this is quite useful if you intend to use that shaded JAR (instead of the normal JAR) as a dependency for another module. That dependency-reduced-pom.xml will not contain the JARs already present in the shaded one, avoiding useless duplication.

like image 142
Tome Avatar answered Sep 22 '22 03:09

Tome


I read the docs about a hundred times or so and still couldn't understand what this is for, what really is the use case for it.

Finally this is what I think: lets say you have a project with dependencies A, B, C, D, E. In the pom.xml you configure the shade plugin in such a way that when it creates the uber-jar (call it foo.jar), it includes A, B, C in the shaded jar but for some reason you decide not to include D, E in the shaded jar even though your project depends on them - a case in point are dependencies that are needed only for testing (e.g. any dependency that has a scope of test and is not included in the shaded jar). The dependency-reduced-pom.xml will define D, E in it. The idea is that if someone wants to use foo.jar the dependency-reduced-pom.xml provides a hint of some sort that beware foo.jar is missing dependencies D, E in it - use at your own risk. You might then decide to explicitly add D, E in the project that will use foo.jar.

So the dependency-reduced-pom.xml is more like missing-dependencies.xml and lists the dependencies which are missing in the uber-jar which is output by the shade plugin.

like image 39
morpheus Avatar answered Sep 25 '22 03:09

morpheus