maven - 如何将特定版本的 jar 包含到 Uber jar 中?
问题描述
在构建我的项目时,maven 下载了依赖项 spark-avro,版本为 1.8.2 和 2.4.3,并且打包错误。
在我的 pom.xml 文件中,我只有 spark-avro 版本 2.4.3,1.8.2 是来自其他地方的传递依赖。
如何指定要包含在 uber jar 中的具体版本?我试着做:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-assembly</finalName>
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>org.shaded.apache.http</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>com.alcon.salesforce.etl:alcon-salesforce-etl</artifact>
<excludes>
<exclude>com/alcon/etl/glue/common/**</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<includes>
this ---------------------> <include>org.apache.avro:spark-avro_2.11:2.4.3</include>
<include>com.alcon.etl.common:*</include>
</includes>
</artifactSet>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>assembly</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
正如您在顶部看到的那样,我在那里编写了 spark-avro 的特定版本,org.apache.avro:spark-avro_2.11:2.4.3
但我在某个地方搞砸了,因为当我提取生成的 jar 的内容时,那里没有火花。
什么是正确的语法?
解决方案
你看错地方了。Maven 首先将依赖项合并到一个列表中(其中每个工件只出现在一个版本中)。您<include>
只是此列表中的一个过滤器。
因此,Maven 在调解传递依赖时可能不会选择您期望的依赖。但我不能肯定地说,因为我没有你的dependency:tree
.
推荐阅读
- python - Python:如何获取列表中的对象,然后返回该对象的值(这是一个变量)?
- python - 在 Python 中按顺序运行 Powershell 命令
- javascript - 在 Excel VBA 中保存网页中 javascript 函数的结果
- sql - 想生成自定义唯一键并同时处理多个请求
- angularjs - 动态启用/禁用滑动器(触摸/鼠标)
- ios - WKWebview 超时
- android-studio - 如何在 Android Studio 中恢复 XML 代码样式设置
- pycharm - 无法接受 PyCharm 的条款和条件
- git - 如何使用 FULL COMMITS 将 git repo 迁移到 svn?
- abap - 如果输入不正确,如何禁用可编辑 ALV 网格?