当前位置: 首页 > 知识库问答 >
问题:

maven-shade-plugin并不取代原来的jar

夹谷苗宣
2023-03-14
  <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>

共有1个答案

海典
2023-03-14

带阴影的插件默认情况下将原始文件保存为-original.jar,如果您想用新生成的(带阴影的)文件替换原始文件,请在您的配置插件部分中添加这一行:

<configuration>
    ...

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

将output.directory替换为shade插件outputdirectory。

更多细节请查看此帖子:post

 类似资料:
  • Maven shade plugin 为 Maven 提供了 Jar 打包的神器,包括将所依赖的 jar 包都打包到一起。

  • 我有一个项目,它使用maven-assembly-plugin打包了几个(可执行的jar)程序集--基本上相同的代码,但针对不同的客户机使用了不同的数据集。 我需要在可执行jar中使用spring,由于spring中的文件命名,我需要使用maven-shade-plugin创建jar。这工作很好,我可以创建可执行的jar,但我不能确定如何将我的其他文件组装到这个新的shaded jar,因为sha

  • 想法? 谢了。

  • 我正在使用maven-shade-plugin在构建的包阶段重新定位一些包。我还使用maven-bundle-plugin生成一个清单。问题是bundle插件在shade插件之前运行(在过程类阶段),并且在生成的清单的导出中没有包含任何我的shade包。 -- 根据要求,我的POM的阴影和捆绑部分: 从这里取的

  • 问题内容: 我想使用Maven-shade-plugin创建uber-jar。但是当我调用命令时,Maven报告有一些重叠的类。我附加了所有有问题的重叠,其中一些是由于库的旧版本和新版本(Log4J)引起的,但是其中一些似乎具有相同的类- 例如javax.mail和mailapi / smtp / imap等。 在这种情况下最好的办法是什么?有一些关键的方法如何确定哪些重叠是安全的,而忽略哪些需要

  • 我阅读了一些关于的的源代码: 是否自动使用dependency-reduced-pom.xml而不是pom.xml? shade插件生成的dependency-reduced-pom.xml的目的是什么? 将dependency-reduced-pom.xml添加到基目录的Maven shade插件 https://maven.apache.org/plugins/maven-shade-plug