我正在处理的项目生成了一个 jar,我将其部署在 azure 上,以便 Spark 运行该作业。 它使用内部依赖项 A,它使用依赖项 org.apache.commons:commons-configuration:1.10,但当我在 azure 上部署时,它默认使用 2.1.1 版本。
在 Azure 上,我们有版本 2.1.1,其中包名称 (org.apache.commons.configuration2) 与 1.10 版本 (org.apache.commons.configuration) 不同。
因此在使用 2.1.1 版本时,依赖 A 中有这一行会导致错误:
Import org.apache.commons.configuration
它需要在末尾有“2”,这是我不能添加的,因为 A 是依赖项。
我尝试从 A 中排除 org.apache.commons:commons-configuration 然后使用 maven shade 插件重命名包但是 jar 文件变成实际大小的两倍,除了单独生成的 shaded jar,而不是在 zip 中使用工作流程和sh 文件,这是我的团队可能不喜欢的东西。
最佳答案
从 commons-configuration 1 更新到 2 是一个重大变化,新版本不是直接替代品。正如您已经指出的顶层包更改,这很可能会破坏库 A。正确的解决方案可能是更新库 A 以使用 commons-configuration 2。
您仍然可以尝试破解 Maven 项目设置以查看它是否有效:
- 使用
<exclude>
从库 A 中排除 commons-configuration 1标签。 - 使用
provided
添加 commons-configuration 2 作为直接项目依赖项模块 B 中的范围。Theprovided
scope is needed to avoid packaging the dependency.
关于java - 较新依赖项中的 Maven 不同包名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68423150/