Maven 阴影插件未执行



在我当前的项目设置中,maven shade插件的执行非常不一致。该插件看起来像是在我构建父模块后执行的,但是在该实例中执行后,它在独立构建子模块时无法执行。

我的父母绒球是

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

还有孩子绒球

<?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>
    </plugins>
</build>

以及使用上面指定的pom在子模块上运行"安装"目标时的构建输出

"C:Program FilesJavajdk1.8.0_131binjava" -Dmaven.multiModuleProjectDirectory=C:Userscnethdevastronuscommonslib-container "-Dmaven.home=C:Program FilesJetBrainsIntelliJ IDEA 2017.1.4pluginsmavenlibmaven3" "-Dclassworlds.conf=C:Program FilesJetBrainsIntelliJ IDEA 2017.1.4pluginsmavenlibmaven3binm2.conf" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2017.1.4libidea_rt.jar=56823:C:Program FilesJetBrainsIntelliJ IDEA 2017.1.4bin" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJetBrainsIntelliJ IDEA 2017.1.4pluginsmavenlibmaven3bootplexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.1.4 install
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for net.astronus:lib-container:jar:0.0.1
[WARNING] The expression ${version} is deprecated. Please use ${project.version} instead.
[WARNING] The expression ${version} is deprecated. Please use ${project.version} instead.
[WARNING] The expression ${version} is deprecated. Please use ${project.version} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building AstroLibContainer 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ lib-container ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ lib-container ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to C:Userscnethdevastronuscommonslib-containertargetclasses
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ lib-container ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:Userscnethdevastronuscommonslib-containersrctestresources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ lib-container ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ lib-container ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ lib-container ---
[INFO] Building jar: C:Userscnethdevastronuscommonslib-containertargetastro-lib-container.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ lib-container ---
[INFO] Installing C:Userscnethdevastronuscommonslib-containertargetastro-lib-container.jar to C:Userscneth.m2repositorynetastronuslib-container.0.1lib-container-0.0.1.jar
[INFO] Installing C:Userscnethdevastronuscommonslib-containerpom.xml to C:Userscneth.m2repositorynetastronuslib-container.0.1lib-container-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.998 s
[INFO] Finished at: 2018-01-11T18:27:32+02:00
[INFO] Final Memory: 18M/199M
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0

如您所见,尽管在父 pom 的<plugins>部分中定义了执行,但 maven shade 插件并未执行。

您需要将插件附加到 maven 执行阶段。请参阅Shade插件文档中的此示例(请参阅它如何附加到package阶段(:

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

最新更新