【发布时间】:2017-05-22 19:56:23
【问题描述】:
我有两个依赖项,artifact-a 和 artifact-b。每个都依赖于不同版本的 artifact-c。如何对工件进行着色以使用这些不同的依赖项? (或者让 artifact-a 使用阴影依赖,而 artifact-b 使用普通依赖。
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-a</artifactId>
<version>2.1.0</version>
<!-- artifact-a uses version 3 of artifact-c.
How do I relocate version 3 without conflicting with version 4?
<groupId>group-c</groupId>
<artifactId>artifact-c</artifactId>
<version>3.0.0</version>
-->
</dependency>
<dependency>
<groupId>group-b</groupId>
<artifactId>artifact-b</artifactId>
<version>1.5.0</version>
<!-- artifact-b uses version 4 of artifact-c.
How do I relocate version 4 without conflicting with version 3?
<groupId>group-c</groupId>
<artifactId>artifact-c</artifactId>
<version>4.0.0</version>
-->
</dependency>
【问题讨论】:
-
您可以尝试在 Maven 阴影配置中使用
<artifactSet> <includes> <include>group-c:artifact-c:*:4.0.0</include> </includes> <excludes> <exclude>group-c:artifact-c:*:3.0.0</exclude> </excludes> </artifactSet>。 -
我认为这是不可能的。通常 Maven 会忽略其中一个依赖项(当您分析依赖项时,它会说“忽略版本 x.y.z”)。除非您使用不同的类加载器完全分离依赖项,否则使用包含相同类的两个不同依赖项将不起作用。
-
@nullpointer 谢谢你,但我不能排除这两个版本的“c”,因为“a”和“b”需要不同版本的“c”。
标签: java maven dependency-management maven-shade-plugin build-dependencies