126

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

6
  • 2
    Isn't it relatively clear in the Mojo doc: maven.apache.org/plugins/maven-shade-plugin/… ?
    – Tome
    Commented Apr 7, 2014 at 7:57
  • 10
    No, there is nothing in there about its purpose. Commented Apr 7, 2014 at 19:56
  • 6
    Well, if you have a module A with X dependencies, and shade some of them in a specific JAR (A-shaded.jar), then you won't need those shaded dependencies if you want to depend on A-shaded.jar instead of A.jar. So the plugin creates a pom.xml containing only the Y non-shaded dependencies.
    – Tome
    Commented Apr 9, 2014 at 14:39
  • 1
  • 2
    I understand what this dependency-reduced POM contains. I'm curious if anyone can describe a real-life workflow in which they are using the dependency-reduced POM? Commented Jun 4, 2023 at 14:05

6 Answers 6

66

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.

5
  • 76
    I'm not sure I agree that anything about mvn is well documented, the technology is inherently difficult to understand. It would be helpful to understand how to use the dependency-reduced-pom.xml. Where and how should it be used. Commented Jan 29, 2016 at 18:12
  • 1
    Above, @ScottBoring asks where the setting should be added. It goes in the configuration block and there is an example of that block within the plugin definition on the maven shade plugin usage page.
    – Jeremy D
    Commented Jun 18, 2016 at 15:52
  • 7
    But how, when you depend on the shaded jar, do you get it to use the drp instead?
    – OrangeDog
    Commented Aug 2, 2016 at 13:54
  • Doesn't the plugin use that drp as the project pom if it is configured to be created (for install and deploy phases for instance)?
    – Tome
    Commented Aug 2, 2016 at 15:12
  • 4
    @JeremyD he's not asking where to use the setting, he's asking where to use the generated POM.
    – Shannon
    Commented Sep 28, 2016 at 23:04
38

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.

1
  • 10
    Can you confirm if this understanding proved correct over time?
    – MsA
    Commented Jul 9, 2019 at 10:45
15

Short Answer

The dependency-reduced-pom.xml removes transitive dependencies which are already in your shaded jar. This prevents consumers from pulling them in twice.

Long Answer

There are several reasons to shade a jar.

If you are producing an executable jar with all of its dependencies bundled, then you are probably uploading it to a package repository and users are downloading it manually. In this scenario, the dependency-reduced-pom.xml doesn't do anything for you.

Another reason is because you are building a library and are using specific versions of other common libraries. You don't want to force your users to use the same version as you. By shading, you effectively namespace those dependencies and your users can then include the same libraries again, but on different versions.

In this case, if you upload the original pom, then users who depend on your library will end up pulling in all dependencies twice. Once from the shaded copies and once from the copies declared in the pom. Uploading the dependency-reduced-pom.xml instead prevents this from happening because the shaded dependency declarations are removed.

2
  • 2
    Should we commit this file or ignore it? Thanks
    – Matteo
    Commented Jun 16, 2021 at 23:46
  • 3
    @Madeo the rule of thumb is to not commit anything that is created from the build process. It will get recreated on every build so it is safe to ignore. Committing it will result in additionally, unnecessary comits. Commented Jun 17, 2021 at 16:00
1

The purpose of dependency-reduced-pom.xml is to show you what is the final dependency set of the artifact that you are preparing.

Let's say artifact X depends on A and B. By embedding B dependency with maven-shade-plugin we create an artifact that depends only on A and this is what dependency-reduced-pom.xml will tell you (B dependency will not be in that file). This is the file that will be installed in Maven repository instead of original pom.xml. It will be used where calculating dependency set of artifact X, so if any other module depends on X it will not depend on B.

0

For any uber jar generated dependency-reduced-pom.xml will contain provided dependency by a run time provider. To simply understand while running an application inside tomcat you may not need to provide Servlet jar which contain classes such as Servlet.class dependencies. It will be provided by Selected Run Time environment.

0

I feel that the current answers address the "what is this file" but not the "why this file", its purpose.

If you build then deploy your shaded jar using e.g. the central-publishing-maven-plugin, the plugin will not deploy the original pom.xml with the shaded jar, but rather the dependency-reduced-pom.xml renamed to pom.xml.

This is because you don't want your Maven central artefact to declare external dependencies which are actually included in your jar.

Not the answer you're looking for? Browse other questions tagged or ask your own question.