Gili
Gili

Reputation: 90003

maven-shade-plugin fails to work across multiple runs

The first time that maven-shade-plugin runs, it:

  1. Uses foobar.jar as input
  2. Outputs foobar-shaded.jar
  3. Copies foobar.jar to original-foobar.jar
  4. Copies foobar-shaded.jar to foobar.jar

This allows the maven-install-plugin to pick up the shaded JAR file and everyone is happy. Unfortunately, the second time you run the build the maven-shade-plugin now picks up the output from the first run as the input of the second run and you will end up with a slew of errors (e.g. overlapping classes/resources).

What is the easiest way to fix the plugin's behavior so it can be run over an over again without a mvn clean step?

Upvotes: 1

Views: 166

Answers (1)

Gili
Gili

Reputation: 90003

The easiest workaround is to instruct the JAR plugin to run even if the source files did not change. This will overwrite the shaded JAR and the maven-shade-plugin will do the right thing:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <id>default-jar</id>
            <configuration>
                <forceCreation>true</forceCreation>
            </configuration>
        </execution>
    </executions>
</plugin>

Upvotes: 1

Related Questions