提问者:小点点

马文阴影插件,用于生产两个罐子


到目前为止,我一直在使用maven汇编插件为每个工件生成两个JAR——编译源和依赖项——原因很简单——在网络上仅部署编译源比部署具有40 MB数据的多合一JAR要快得多。

由于覆盖了内部文件,我不得不切换到maven shade插件才能使用

<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包时,只运行第二次执行。第一个总是被忽略。使用maven汇编插件,它工作得很好。

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


共1个答案

匿名用户

与其定义两次插件,不如简单地定义一次,但有两个执行部分。所以在你的情况下是:

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