当前位置: 首页 > 知识库问答 >
问题:

Maven阴影插件未执行

万涵亮
2023-03-14

在我当前的项目设置中,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>

还有孩子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>
    </plugins>
</build>

以及在具有上述pom的子模块上运行“安装”目标时的构建输出

"C:\Program Files\Java\jdk1.8.0_131\bin\java" -Dmaven.multiModuleProjectDirectory=C:\Users\cneth\dev\astronus\commons\lib-container "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\lib\idea_rt.jar=56823:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\plugins\maven\lib\maven3\boot\plexus-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:\Users\cneth\dev\astronus\commons\lib-container\target\classes
[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:\Users\cneth\dev\astronus\commons\lib-container\src\test\resources
[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:\Users\cneth\dev\astronus\commons\lib-container\target\astro-lib-container.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ lib-container ---
[INFO] Installing C:\Users\cneth\dev\astronus\commons\lib-container\target\astro-lib-container.jar to C:\Users\cneth\.m2\repository\net\astronus\lib-container\0.0.1\lib-container-0.0.1.jar
[INFO] Installing C:\Users\cneth\dev\astronus\commons\lib-container\pom.xml to C:\Users\cneth\.m2\repository\net\astronus\lib-container\0.0.1\lib-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

如您所见,尽管在< code >中定义了执行,maven shade插件并没有执行

共有1个答案

陈功
2023-03-14

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

<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> 
 类似资料:
  • 有问题的错误消息是 从文件夹中的工作正常。我的项目结构是 还有由定义 由下式定义 这是一个比这个问题中的版本修复升级晚得多的版本 插件在子模块pom而不是父pom中,因为这里的错误 我尝试删除

  • 我试图使用maven-shade-plugin来区分Java6和Java7工件。从这个链接我的理解是原来的神器会被阴影的那个替换掉 然而,它正在安装没有阴影分类器。下面是我的shade插件配置:

  • 以下部分显示了my pom.xml中shade插件的配置: 然而,一些被排除的文件(似乎??)被偷偷地放入输出jar文件中: 那么,阴影插件配置中有什么不正确的地方呢?

  • 我需要从shade插件中排除log4j工件,以避免log4j漏洞,但是,artifactSet下的exclude标记似乎不起作用。有没有解决这个问题的建议? 我不断发现以下错误:未能执行目标组织。阿帕奇。专家插件:maven shade插件:3.2.4:shade(默认值)on project:目标组织的执行默认值。阿帕奇。专家插件:maven shade插件:3.2.4:shade失败:插件组织

  • 在maven包中,我有一个奇怪的行为。我有一个工件“A”,它取决于“B”。 在“A”中,我有一个包含persistence.xml的META-INF文件夹,在“B”中,我也有一个包含persistence.xml的META-INF文件夹。 这是pom关于shade插件和依赖项的文件A 考虑到“B”也是一个阴影工件,如何从“B”中排除持久.xml文件?

  • 阴影 Unity 的灯光可以将 阴影 从一个游戏对象投射到自身的其他部分或是附近的其他游戏对象上。阴影以『扁平』的方式体现游戏对象的尺寸和位置,因此可以为场景添加一定程度的深度和真实感。 场景视图中的游戏对象正在投射阴影 阴影如何工作? 考虑一种最简单的情况,在场景中只有单个光源。光线从光源出发并沿着直线传播,最终可能会碰撞到场景中的游戏对象。一旦光线碰撞到某个游戏对象,光线将无法继续传播和照亮前