此功能已添加到 maven-shade-plugin(刚刚发布)的 1.6 版中。minimizeJar 现在不会删除专门包含在过滤器中的类。请注意,在筛选器中包含项目的某些类将排除该项目的非指定类,因此请确保包括所需的所有类。
下面是一个示例插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>log4j:log4j</artifact>
<includes>
<include>**</include>
</includes>
</filter>
<filter>
<artifact>commons-logging:commons-logging</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
若要仅包含特定类,请在筛选器的类名中使用路径斜杠将它们添加为包含(同样,将自动排除未包含的类)。
<filter>
<artifact>org.yourorg:your-artifact</artifact>
<includes>
<include>org/yourorg/yourartifact/api/*</include>
<include>org/yourorg/yourartifact/util/*</include>
</includes>
</filter>