Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is dependency-reduced-pom.xml automatically used instead of pom.xml?

Is dependency-reduced-pom.xml created by Maven shade plugin automatically used in projects that depends on the uberjar (instead of the ordinary pom.xml)?

Asking this after reading a number of dependency-reduced-pom.xml related questions and haven't found the answer yet:

Maven shade plugin adding dependency-reduced-pom.xml to base directory

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

What is `dependency-reduced-pom.xml` file which created when calling maven package command?

like image 215
Johnny Avatar asked Feb 02 '16 13:02

Johnny


People also ask

What is dependency reduced POM XML?

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

What happens if you don't specify version in POM XML?

of your question: If you don't specify a version there are various different outcomes: a) you will get an error... b) if you have defined the version in the dependency management of the project's parent's pom, then that version is taken. The parent of the project doesn't have to be an enclosing superproject.

What happens when we add dependency in POM XML?

If the dependency/jar is found here then it add the jar file to you build path. After that it uses required class file from the jar for compilation. If the dependency is not found in ~/. m2 then it looks for your local private repository (If you already have configured any using setting.


1 Answers

The dependency-reduced-pom.xml is generated at build time into ${basedir} of the project. This file is a temporary file that is only used for packaging into the shaded jar. Quoting the documentation of the createDependencyReducedPom attribute:

Flag whether to generate a simplified POM for the shaded artifact. If set to true, dependencies that have been included into the uber JAR will be removed from the <dependencies> section of the generated POM. The reduced POM will be named dependency-reduced-pom.xml and is stored into the same directory as the shaded artifact. Unless you also specify dependencyReducedPomLocation, the plugin will create a temporary file named dependency-reduced-pom.xml in the project basedir.

To make it clear, after the maven-shade-plugin has run:

  • your initial POM will be left unchanged;
  • a temporary file that you can completely ignore named dependency-reduced-pom.xml will have been generated inside the root folder (this is considered an open issue with this plugin);
  • the shaded artifact will contain your initial POM unchanged inside the META-INF directory and not the reduced POM (this is not really important but better mention it - there was an issue about this that was closed automatically: MSHADE-36);
  • the POM that will be deployed is the reduced POM;
  • the shaded artifact will be by default the main artifact of the project.
like image 130
Tunaki Avatar answered Sep 19 '22 19:09

Tunaki