本文介绍了maven-shade-plugin 不会替换原来的 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
奇怪的是,我的 maven-shade-plugin 没有用带阴影的 jar 替换原来的 jar.有谁知道可能是什么原因?
这是我在 pom.xml 中的插件
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><version>${plugin.shade.version}</version><配置><工件集><排除><!-- 保持 slf4j 无阴影,以便下游用户可以配置日志记录.--><exclude>org.slf4j:slf4j-api</exclude><exclude>org.slf4j:slf4j-log4j12</exclude><!-- 使 commons-logging 保持无阴影,以便下游用户可以配置日志记录.--><exclude>commons-logging:commons-logging</exclude><!-- 保持 commons-exec 无阴影,以便下游用户可以使用 ProcessLauncher.--><exclude>org.apache.commons:commons-exec</exclude><!-- 让 log4j 保持无阴影,以便下游用户可以配置日志记录.--><exclude>log4j:log4j</exclude></排除></artifactSet><过滤器><过滤器><神器>*:*</神器><排除><exclude>META-INF/*.SF</exclude><exclude>META-INF/*.DSA</exclude><exclude>META-INF/*.RSA</exclude></排除></过滤器></过滤器><变形金刚><transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/><transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"><resource>reference.conf</resource></变压器><transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/><transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"><resource>NOTICE.txt</resource></变压器><transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"><resource>META-INF/LICENSE.txt</resource><file>${basedir}/../../LICENSE.txt</file></变压器><transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"><resource>META-INF/NOTICE.txt</resource><file>${basedir}/../../NOTICE.txt</file></变压器></变形金刚><搬迁><搬迁><pattern>org</pattern><shadedPattern>${shaded.dependency.prefix}.org</shadedPattern><排除><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><!-- 不是 jdk 一部分的 org/包 --><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></排除></搬迁><搬迁><pattern>com.google</pattern><shadedPattern>${shaded.dependency.prefix}.com.google</shadedPattern></搬迁><搬迁><pattern>io</pattern><shadedPattern>${shaded.dependency.prefix}.io</shadedPattern></搬迁><搬迁><pattern>com.esotericsoftware</pattern><shadedPattern>${shaded.dependency.prefix}.com.esotericsoftware</shadedPattern></搬迁></relocations></配置><执行><执行><phase>包</phase><目标><目标>阴影</目标></目标></执行></执行></插件>
解决方案
Shaded plugin 默认保存原文件为-original.jar,如果你想用新生成的(shaded)替换原文件,把这行放在你的配置插件部分:
...<outputFile>${output.directory}\${project.artifactId}-${project.version}.jar</outputFile>...</配置>用你的阴影插件 outputDirectory 替换 output.directory.
查看此帖子了解更多详情:帖子
It is weird that, my maven-shade-plugin doesn't replacing the original jar with the shaded jar. Does anyone know what could be the reason ?
Here's my plugin in 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>
解决方案
Shaded plugin by default save original file as -original.jar, if you want to replace original file with the new generated (shaded), put this line in your configuration plugin section:
<configuration>
...
<outputFile>${output.directory}\${project.artifactId}-${project.version}.jar</outputFile>
...
</configuration>
Replace output.directory with your shade plugin outputDirectory.
Check this post with more details: post
这篇关于maven-shade-plugin 不会替换原来的 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!