gpt4 book ai didi

Maven Shade 插件生成两个 Jars

转载 作者:行者123 更新时间:2023-12-03 06:02:15 26 4
gpt4 key购买 nike

到目前为止,我一直在使用 Maven 程序集插件为每个 Artifact 生成两个 JAR - 已编译的源代码和依赖项 - 原因很简单 - 通过网络仅部署已编译的源代码比部署一体化 JAR 快得多具有 40 MB 的数据。

由于覆盖了内部文件,我必须切换为 Maven Shade 插件才能使用 <transformers>特征。但是我无法同时运行这两个执行:

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-libs</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
<artifactSet>
<excludes>
<exclude>...</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-main</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}.jar</outputFile>
<artifactSet>
<includes>
<include>...</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

当我运行mvn package时,只运行第二次执行。第一个总是被忽略。使用 Maven 组装插件,它工作得很好。

当然解决方案可以是同时使用程序集和阴影插件,但我希望找到更一致的解决方案。

最佳答案

不要定义插件两次,只需定义一次但有两个 execution 部分。所以在你的情况下它会是:

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-libs</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
<artifactSet>
<excludes>
<exclude>...</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
<execution>
<id>shade-main</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}.jar</outputFile>
<artifactSet>
<includes>
<include>...</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

关于Maven Shade 插件生成两个 Jars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17845423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com