Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

java - Maven shade plugin not executing

In my current project setup, the maven shade plugin is executing extremely inconsistently. The plugin looks like its executing after I build the parent module, however after executing in that instance it fails to execute when building the child modules independently.

My parent pom is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.astronus</groupId>
<artifactId>commons-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>common</module>
    <!--<module>server-preparer</module>
    <module>papi-placeholders</module>
    <module>papi-base</module>
    <module>server-template</module>
    <module>message-replace</module>
    <module>skyblock-addons</module>-->
    <module>lib-container</module>
</modules>

<properties>
    <shade.basepattern>net.astronus.thirdparty</shade.basepattern>
</properties>

<repositories>
    <repository>
        <id>bungeecord-repo</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
    <repository>
        <id>spigot-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
    <repository>
        <id>placeholderapi</id>
        <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
    </repository>
    <repository>
        <id>dmulloy2-repo</id>
        <url>http://repo.dmulloy2.net/nexus/repository/public/</url>
    </repository>
    <repository>
        <id>luck-repo</id>
        <url>http://repo.lucko.me/</url>
    </repository>
</repositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.4-jre</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.8.8-R0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>me.lucko.luckperms</groupId>
            <artifactId>luckperms-api</artifactId>
            <version>4.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>me.clip</groupId>
            <artifactId>placeholderapi</artifactId>
            <version>2.8.2</version>
        </dependency>
        <dependency>
            <groupId>net.astronus</groupId>
            <artifactId>common</artifactId>
            <version>${version}</version>
        </dependency>
        <dependency>
            <groupId>net.astronus</groupId>
            <artifactId>papi-base</artifactId>
            <version>${version}</version>
        </dependency>
        <dependency>
            <groupId>net.astronus</groupId>
            <artifactId>server-template</artifactId>
            <version>${version}</version>
        </dependency>
        <dependency>
            <groupId>com.comphenix.protocol</groupId>
            <artifactId>ProtocolLib-API</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>net.md-5</groupId>
            <artifactId>bungeecord-api</artifactId>
            <version>1.12-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>me.lucko</groupId>
            <artifactId>helper</artifactId>
            <version>4.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>

    <resources>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.3</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.5</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>update-parent</goal>
                        <goal>update-child-modules</goal>
                    </goals>
                    <configuration>
                        <allowSnapshots>true</allowSnapshots>
                        <generateBackupPoms>false</generateBackupPoms>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <shadedArtifactAttached>false</shadedArtifactAttached>
                <relocations>
                    <relocation>
                        <pattern>com.google</pattern>
                        <shadedPattern>${shade.basepattern}.com.google</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>org.apache</pattern>
                        <shadedPattern>${shade.basepattern}.org.apache</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

And the child pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <artifactId>commons-parent</artifactId>
    <groupId>net.astronus</groupId>
    <version>0.0.1</version>
</parent>

<artifactId>lib-container</artifactId>
<name>AstroLibContainer</name>
<description>Bukkit/Spigot plugin containing libraries used by astronus bukkit/spigot projects</description>
<packaging>jar</packaging>

<properties>
    <astronus.relocate>true</astronus.relocate>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>net.astronus</groupId>
        <artifactId>common</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>net.md-5</groupId>
        <artifactId>bungeecord-api</artifactId>
        <type>jar</type>
        <version>1.12-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <finalName>astro-lib-container</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <configuration combine.children="append">
                <artifactSet>
                    <includes>
                        <include>com.google.guava:guava</include>
                        <include>commons-io:commons-io</include>
                        <include>net.astronus:common</include>
                    </includes>
                </artifactSet>
            </configuration>
        </plugin>
    <

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to attache the plugin to maven execution phase. See this sample from Shade plugin documentation (see how it is attaching to package phase):

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <!-- put your configurations here -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...