gpt4 book ai didi

java - maven-shade-plugin:排除依赖项及其所有传递依赖项

转载 作者:搜寻专家 更新时间:2023-10-31 08:22:39 26 4
gpt4 key购买 nike

使用 maven-shade-plugin,有没有办法排除依赖项(未提供)及其所有传递依赖项

例如:

<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

... other dependencies

</dependencies>

和 1)

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
<excludes>
<exclude>com.example:some-artifact</exclude>
</excludes>
</artifactSet>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

或 2)

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>com.example:some-artifact</artifact>
<excludes>
<exclude>**</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

那些不起作用。

com.example:some-artifact 的所有传递依赖项都添加到最终的 jar 中。

请注意,我不想将 com.example:some-artifact 的范围设置为 provided

最佳答案

从配置文件中运行“shade”,并将您的依赖项标记为仅在该配置文件中提供。例如:

<profiles>
<profile>
<id>shadeProfile</id>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>some-artifact</artifactId>
<version>1.23</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedClassifierName>shaded</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

当您运行 mvn -PshadeProfile package 时,它将按照提供的方式处理您的依赖项(因此忽略其依赖项),并且它将使用分类器“shaded”,因此您可以将其用作依赖项其他模块。

关于java - maven-shade-plugin:排除依赖项及其所有传递依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28458058/

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