Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven shade plugin remove "original"

Each time I run maven package to produce an updated jar, it creates an "original" jar file, as well as the updated one.

This is particularly an issue for me due to the fact that I'm running the compiled jar automatically, and they're both trying to start.

All I want created is the ${project.artifactId}-${project.version}-shaded.jar file produced, and not the "original" one. Is there a way to have it just overwrite without making a backup (I'm assuming that's what it's doing)?

How can I solve this?

Here is my pom:

<groupId>com.spiromarshes</groupId>
<artifactId>LiveDebugTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>LiveDebugTest</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <defaultGoal>clean package</defaultGoal>
    <plugins>
        <plugin>
            <version>3.6.1</version>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <minimizeJar>true</minimizeJar>
                        <outputDirectory>${dir}</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<repositories>
    <repository>
        <id>spigotmc-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
    </repository>
    <repository>
        <id>sonatype</id>
        <url>https://oss.sonatype.org/content/groups/public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.12.2-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

like image 266
trev915 Avatar asked Jun 19 '18 00:06

trev915


2 Answers

Solved by using <outputFile>${dir}/${project.artifactId}.jar</outputFile> under the configuration section for maven-shade-plugin.


Full example, for context:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.4</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <outputFile>${dir}/${project.artifactId}.jar</outputFile>
      <filters>
        <filter>
          <artifact>*:*</artifact>
          <excludes>
            <exclude>META-INF/MANIFEST.MF</exclude>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
            <exclude>META-INF/*.RSA</exclude>
          </excludes>
        </filter>
      </filters>
    </configuration>
  </plugin>
like image 92
trev915 Avatar answered Oct 19 '22 14:10

trev915


The original Maven intended file name for the package includes the version number.
There is a shade-plugin configuration that not only prevents the "original"-prefixed file name, but also achieves the original Maven package name.

        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        <finalName>${project.artifactId}-${project.version}</finalName>
                        ..                          ..
                        .. more shade configuration ..
                        ..                          ..
                    </configuration>
                </execution>
            </executions>
        </plugin>
like image 42
Sven Döring Avatar answered Oct 19 '22 15:10

Sven Döring