71

The maven shade plugin is creating a file called dependency-reduced-pom.xml and also artifactname-shaded.jar and placing them in the base directory.

Is this a bug? Should be in the target directory. Any workaround?

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
DD.
  • 21,498
  • 52
  • 157
  • 246

6 Answers6

83

You can avoid having it created by setting createDependencyReducedPom to false.

e.g.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>${maven-shade-plugin.version}</version>
    <configuration>
        <createDependencyReducedPom>false</createDependencyReducedPom>
    </configuration>
    ....
    ....
</plugin>

See http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#createDependencyReducedPom

<createDependencyReducedPom>

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 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.

  • Type: boolean
  • Required: No
  • Default: true
xverges
  • 4,608
  • 1
  • 39
  • 60
  • 20
    If you turn it off, then the thing you build will still have all the merged-in dependencies listed as dependencies. – bmargulies Jul 04 '12 at 17:35
22

Based on bmargulies' answer and his comment on Xv.'s answer, I decided to configure the dependency-reduced POM to be output to target/, which is already ignored in my VCS.

To do that, I just added the dependencyReducedPomLocation element to the configuration element of the plugin, i.e.

<configuration>
  <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
  (...)
</configuration>
Zoltán
  • 21,321
  • 14
  • 93
  • 134
  • 3
    Bevare of this, from the plugin documentation "Where to put the dependency reduced pom. Note: setting a value for this parameter with a directory other than ${basedir} will change the value of ${basedir} for all executions that come after the shade execution. This is often not what you want. This is considered an open issue with this plugin." – Alexander Pogrebnyak Nov 16 '16 at 20:40
10

See https://issues.apache.org/jira/browse/MSHADE-121, and also https://issues.apache.org/jira/browse/MSHADE-124.

There is an option to move the d-r-p to elsewhere, but you may not like the consequences.

You are wrong about the -shaded jar, it always ends up in target/ unless you move it elsewhere.

Sander Verhagen
  • 8,540
  • 4
  • 41
  • 63
bmargulies
  • 97,814
  • 39
  • 186
  • 310
3

You could use an old version of the plugin. Version 1.7 of the maven-shade-plugin writes to /target.

Since version 1.7.1, dependency-reduced pom.xml is written to basedir. See the issue MSHADE-124 for some reasons why it was done and what the consequences are. If you try setting dependencyReducedPomLocation, you will likely run into problems generating the site - open issue MSHADE-145.

0

the documentation on http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html is incorrect when it says:

createDependencyReducedPom boolean - 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 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. Default value is: true.

the dependency-reduced-pom.xml is not stored in the same directory as the shaded artifact (target directory) ... it is in fact generated in the base directory, not target

Luís Ramalho
  • 10,018
  • 4
  • 52
  • 67
nanite
  • 37
  • 2
  • 8
    they write (even in your answer you can see): "the plugin will create a temporary file named dependency-reduced-pom.xml in the project basedir" – OhadR Nov 06 '14 at 19:02
0

To ignore the file you can add it to the ignore directive for your DVCS. For git, a .gitignore file is created with contents:

dependency-reduced-pom.xml

You can also add it to maven-clean-plugin configuration so it's blown away during the clean lifecycle phase: (Below assumes defaults, such as version, are defined in the POMs pluginManagement section.)

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>.</directory>
                                <includes>
                                    <include>**/dependency-reduced-pom.xml</include>
                                </includes>
                                <followSymlinks>false</followSymlinks>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
            </plugins>
        </build>

Note that the above configuration is additive to the non-customized clean default.

ingyhere
  • 11,818
  • 3
  • 38
  • 52