【问题标题】:Maven Shade Plugin to produce two JarsMaven Shade Plugin 生成两个罐子
【发布时间】:2013-07-24 21:51:42
【问题描述】:

到目前为止,我一直在使用 maven 程序集插件为每个工件生成两个 JAR - 已编译的源代码和依赖项 - 原因很简单 - 通过网络仅部署已编译的源代码比部署 all-in-one-JAR 快得多有 40 MB 的数据。

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

<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 程序集插件,它可以完美运行。

当然解决方案可以是同时使用程序集和阴影插件,但我想找到更一致的解决方案。

【问题讨论】:

  • 您是否尝试过在单个插件定义中定义第二个execution,而不是两次定义插件?
  • 如果你把它作为答案发布,我会接受它。
  • 谢谢,现在已经完成了。很高兴听到它解决了您的问题。

标签: maven maven-assembly-plugin maven-shade-plugin


【解决方案1】:

不要定义插件两次,只需定义一次,但有两个 execution 部分。所以在你的情况下,它会是:

<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>

【讨论】:

  • 这会运行 Shade 两次吗?一次执行就需要永远!
猜你喜欢
  • 2014-06-07
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
  • 2019-03-04
  • 2013-08-19
  • 2013-02-19
  • 2013-04-11
  • 1970-01-01
相关资源
最近更新 更多