在我项目的 pom.xml 中,我有以下依赖项:
<dependency>
<groupId>com.my.library</groupId>
<artifactId>MyLib</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
<dependency>
...
</dependency>
我希望我的项目最终构建的 jar 包含上述 com.my.library:MyLib
依赖项的类,所以我使用了 maven-shade-plugin通过以下方式:
<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>
<filters>
<filter>
<artifact>com.my.library:MyLib</artifact>
<includes>
<include>com/my/library/**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
然后,我运行 mvn clean install
,我的项目构建成功。
但是当我检查 target/
目录下的 MyProject.jar 的内容时,它不包含来自 com.my.library:MyLib
依赖,为什么? maven-shade-plugin 我哪里错了?
最佳答案
定义一个 <artifactSet>
:
<artifactSet>
<includes>
<include>com.my.library:MyLib</include>
</includes>
</artifactSet>
然后尝试删除 <artifact/>
来自 <filters/>
.这应该可以做到。
关于maven - 使用maven-shade-plugin,但是依赖类不在最终的jar中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821017/