Maven shade 插件使用

Maven shade plugin usage

以下部分显示了我 pom.xml 中 shade 插件的配置:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <artifactSet>
            <excludes>
              <exclude>META-INF/*.SF</exclude> 
              <exclude>META-INF/*.DSA</exclude> 
              <exclude>META-INF/*.RSA</exclude> 
              <exclude>META-INF/ECLIPSE*</exclude> 
          </excludes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>

但是一些被排除在外的文件(似乎是??)偷偷进入了输出 jar 文件:

02:19:43/xt $jar -tvf target/ignitedemo-1.0-SNAPSHOT.jar | grep  META | egrep "RSA|DSA|SF"
  9958 Sun Jul 05 02:19:26 PDT 2015 META-INF/ECLIPSEF.SF
  5639 Sun Jul 05 02:19:26 PDT 2015 META-INF/ECLIPSEF.RSA

那么shade插件配置有什么问题呢?

<artifactSet> 用于include/exclude 工件 但它不是排除单个文件的正确位置。

您需要为此使用 <filters>

<filter>
  <artifact>*:*</artifact>
  <excludes>
    <exclude>META-INF/*.SF</exclude> 
    <exclude>META-INF/*.DSA</exclude> 
    <exclude>META-INF/*.RSA</exclude> 
    <exclude>META-INF/ECLIPSE*</exclude> 
  </excludes>
</filter>

使用 artifactSet 您可以指定应排除哪些工件。您必须使用 filters,请参阅 http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html

(ps。你是怎么得到你的 pom 配置的?)