簡體   English   中英

maven-shade-plugin不會取代原來的jar

[英]maven-shade-plugin doesn't replace the original jar

奇怪的是,我的maven-shade-plugin並沒有用陰影罐取代原來的罐子。 有誰知道可能是什么原因?

這是我在pom.xml中的插件

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>${plugin.shade.version}</version>
    <configuration>
      <artifactSet>
        <excludes>
          <!-- Leave slf4j unshaded so downstream users can configure logging. -->
          <exclude>org.slf4j:slf4j-api</exclude>
          <exclude>org.slf4j:slf4j-log4j12</exclude>
          <!-- Leave commons-logging unshaded so downstream users can configure logging. -->
          <exclude>commons-logging:commons-logging</exclude>
          <!-- Leave commons-exec unshaded so downstream users can use ProcessLauncher. -->
          <exclude>org.apache.commons:commons-exec</exclude>
          <!-- Leave log4j unshaded so downstream users can configure logging. -->
          <exclude>log4j:log4j</exclude>
        </excludes>
      </artifactSet>
      <filters>
        <filter>
          <artifact>*:*</artifact>
          <excludes>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
            <exclude>META-INF/*.RSA</exclude>
          </excludes>
        </filter>
      </filters>
      <transformers>
        <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
          <resource>reference.conf</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
        <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
          <resource>NOTICE.txt</resource>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
          <resource>META-INF/LICENSE.txt</resource>
          <file>${basedir}/../../LICENSE.txt</file>
        </transformer>
        <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
          <resource>META-INF/NOTICE.txt</resource>
          <file>${basedir}/../../NOTICE.txt</file>
        </transformer>
      </transformers>
      <relocations>
        <relocation>
          <pattern>org</pattern>
          <shadedPattern>${shaded.dependency.prefix}.org</shadedPattern>
          <excludes>
            <exclude>org/apache/zeppelin/*</exclude>
            <exclude>org/apache/zeppelin/**/*</exclude>
            <exclude>org/apache/thrift/*</exclude>
            <exclude>org/apache/thrift/**/*</exclude>
            <exclude>org/slf4j/*</exclude>
            <exclude>org/slf4j/**/*</exclude>
            <exclude>org/apache/commons/logging/*</exclude>
            <exclude>org/apache/commons/logging/**/*</exclude>
            <exclude>org/apache/commons/exec/*</exclude>
            <exclude>org/apache/commons/exec/**/*</exclude>
            <exclude>org/apache/log4j/*</exclude>
            <exclude>org/apache/log4j/**/*</exclude>
            <exclude>org/sonatype/*</exclude>
            <exclude>org/sonatype/**/*</exclude>
            <exclude>**/pom.xml</exclude>

            <!-- Not the org/ packages that are a part of the jdk -->
            <exclude>org/ietf/jgss/*</exclude>
            <exclude>org/omg/**/*</exclude>
            <exclude>org/w3c/dom/*</exclude>
            <exclude>org/w3c/dom/**/*</exclude>
            <exclude>org/xml/sax/*</exclude>
            <exclude>org/xml/sax/**/*</exclude>
          </excludes>
        </relocation>
        <relocation>
          <pattern>com.google</pattern>
          <shadedPattern>${shaded.dependency.prefix}.com.google</shadedPattern>
        </relocation>
        <relocation>
          <pattern>io</pattern>
          <shadedPattern>${shaded.dependency.prefix}.io</shadedPattern>
        </relocation>
        <relocation>
          <pattern>com.esotericsoftware</pattern>
          <shadedPattern>${shaded.dependency.prefix}.com.esotericsoftware</shadedPattern>
        </relocation>
      </relocations>
    </configuration>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

默認情況下,着色插件將原始文件保存為-original.jar,如果要使用新生成的(陰影)替換原始文件,請將此行放在配置插件部分中:

<configuration>
    ...

    <outputFile>${output.directory}\${project.artifactId}-${project.version}.jar</outputFile>
    ...
</configuration>

用您的shade插件outputDirectory替換output.directory。

查看此帖更多詳細信息: 發布

看起來配置標記應該位於層次結構中的執行標記內,如下所示。 請重新組織執行和執行標記,並在其下包含您的配置,如下所示。

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven.shade.plugin}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>org.apache*</pattern>
                                    <shadedPattern>shaded.org.apache*</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>com.cookie*</pattern>
                                    <shadedPattern>shaded.com.cookie*</shadedPattern>
                                </relocation>
                            </relocations>

                        </configuration>
                    </execution>
                </executions>

            </plugin>

        </plugins>

有關更多信息,請參閱maven文檔http://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM