在我的项目的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我哪里错了?
答案 0 :(得分:1)
定义<artifactSet>
:
<artifactSet>
<includes>
<include>com.my.library:MyLib</include>
</includes>
</artifactSet>
然后尝试从<artifact/>
中移除<filters/>
。这应该做到。
答案 1 :(得分:0)
将模式更改为
<includes>
<include>com/my/library/**.class</include>
</includes>