Maven Shade插件可产生两个罐子 [英] Maven Shade Plugin to produce two Jars

查看:136
本文介绍了Maven Shade插件可产生两个罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直使用maven程序集插件为每个工件生成两个JAR-编译源和依赖关系-原因很简单-通过网络仅部署编译源比部署多合一JAR快得多40 MB的数据.

Till now I was using maven assembly plugin to generate two JARs for each artifact - compiled sources and dependencies - the reason for this was simple - deploying only the compiled sources over network is significantly faster than deploying all-in-one-JAR with 40 MB of data.

由于内部文件的覆盖,我不得不切换到maven shade插件才能使用<transformers>功能.但是,我无法同时运行这两个执行:

Because of overwriting of inner files I had to switch for maven shade plugin to be able to use the <transformers> feature. However I am unable to manage to run both of the two executions:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-libs</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
          <artifactSet>
            <excludes>
              <exclude>...</exclude>
            </excludes>
          </artifactSet>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.handlers</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.schemas</resource>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-main</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}.jar</outputFile>
          <artifactSet>
            <includes>
              <include>...</include>
            </includes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

当我运行mvn package时,仅运行第二次执行.第一个总是被忽略.使用maven程序集插件,它可以完美运行.

When I run mvn package, only the second execution is run. The first one is always ignored. With maven assembly plugin it worked perfectly.

当然,解决方案可能是同时使用Assembly和shade插件,但我想找到更一致的解决方案.

Of course the solution could be to use both assembly and shade plugin at the same time, but I would like to find more consistent solution.

推荐答案

与其定义两次插件,不如定义一次插件,而是使用两个execution部分.因此,根据您的情况,它将是:

Instead of defining the plugin twice, simply define it once but with two execution sections. So in your situation it would be:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-libs</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
          <artifactSet>
            <excludes>
              <exclude>...</exclude>
            </excludes>
          </artifactSet>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.handlers</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.schemas</resource>
            </transformer>
          </transformers>
        </configuration>
      </execution>
      <execution>
        <id>shade-main</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}.jar</outputFile>
          <artifactSet>
            <includes>
              <include>...</include>
            </includes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

这篇关于Maven Shade插件可产生两个罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆