- maven-shade-plugin 使用介绍
- 1 功能描述
- 2 使用案例
- 3 相关配置介绍
- 3.1 设置依赖-includes
- 3.2 排除不需要打包的依赖-excludes
- 3.3 filter 过滤设置
- 3.4 relocations 包重命名
- 3.5 minimizeJar 自动适配依赖
- 3.6 生成一个可执行的jar
- 把整个项目及其它的依赖都打包到一个 “xxx.jar” 中
- 打包冲突,重命名操作
博主使用案例:加强flink-connector-es 组件,在不改变源码的前提下,将加强功能与源码打包到一个jar中,替换官方提供的源码,很好解决版本更新开发成本高
3 相关配置介绍 3.1 设置依赖-includesorg.apache.maven.plugins maven-shade-plugin 3.3.0 shade-flink package shade false // *:* 表示将当前包与所有依赖包全部打包到一个jar中 // 语法:groupId:artifactId:version // * 标识全部 *:* // 排除某些包及文件 // 语法: com.carrotsearch:hppc com.tdunning:t-digest joda-time:joda-time net.sf.jopt-simple:jopt-simple org.elasticsearch:jna org.hdrhistogram:HdrHistogram org.yaml:snakeyaml META-INF/*.SF META-INF/*.DSA META-INF/*.RSA *.properties *.config *.txt org.elasticsearch:elasticsearch config/** modules.txt plugins.txt org/joda/** org.elasticsearch.client:elasticsearch-rest-high-level-client forbidden/** org.apache.httpcomponents:httpclient mozilla/** org.apache.lucene:lucene-analyzers-common org/tartarus/** *:* META-INF/versions/** META-INF/services/com.fasterxml.** META-INF/services/org.apache.lucene.** META-INF/services/org.elasticsearch.** META-INF/LICENSE.txt org.apache.commons org.apache.flink.elasticsearch6.shaded.org.apache.commons org.apache.http org.apache.flink.elasticsearch6.shaded.org.apache.http org.apache.lucene org.apache.flink.elasticsearch6.shaded.org.apache.lucene org.elasticsearch org.apache.flink.elasticsearch6.shaded.org.elasticsearch com.fasterxml.jackson org.apache.flink.elasticsearch6.shaded.com.fasterxml.jackson
3.2 排除不需要打包的依赖-excludes// *:* 表示当前包及依赖包全部打包 // 语法:groupId:artifactId:version // * 表示全部 *:* com.fasterxml.jackson.core:*
3.3 filter 过滤设置// 排除指定包groupId:artifactId joda-time:joda-time // 排序包META-INF目录后缀为SF所有文件META-INF/*.SF // 排序properties后缀的所有文件 *.properties
// 指定某个包做特定的过滤3.4 relocations 包重命名org.elasticsearch.client:elasticsearch-rest-high-level-client forbidden/**
// 打包后将org.apache.commons路径全部替换为org.apache.flink.elasticsearch6.shaded.org.apache.commons
org.apache.commons org.apache.flink.elasticsearch6.shaded.org.apache.commons
// 指定那些包不重名
org.apache.commons.xml.Xpp3Dom
org.apache.commons.xml.pull.*
3.5 minimizeJar 自动适配依赖
此设置支持自动移除项目中没有使用到的依赖,以此来最小化 jar 包的体积
3.6 生成一个可执行的jartrue
... ... org.sonatype.haven.xxx



