首页 > 解决方案 > Maven:依赖项:解包/如何覆盖工件依赖项?

问题描述

我正在开发一个 maven 项目,该项目依赖于一些工件(此处命名为“artifact1”),它使用依赖项解决:解包:

pom.xml 提取:

<project>
  [...]
  <build>
    <plugins>
    [...]
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.0.0</version>
        
        <executions>
            <execution>
                <id>unpack</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>com.xxx.xxx</groupId>
                            <artifactId>artifact1</artifactId>
                            <version>100.1.1</version>
                            <type>zip</type>
                            [...]
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
        </plugin>
    [...]
    </build>
  [...]
</project>

“artifact1”有它自己的依赖:

[INFO] +- com.xxx.xxx:artifact1:zip:100.1.1:compile
[INFO] |  \- com.xxx.xxx:artifact2:zip:100.1.1:compile
[INFO] |     +- com.xxx.xxx:xxx:artifact3:zip:100.1.1:compile

我正在寻找一种方法来覆盖“artifact3”的版本(让我们说版本 100.1.2)(不修改 artifact1 项目本身的任何内容)

预期结果,在上面使用 pom.xml 运行 mvn dependency:tree 并获取依赖树:

[INFO] +- com.xxx.xxx:artifact1:zip:100.1.1:compile
[INFO] |  \- com.xxx.xxx:artifact2:zip:100.1.1:compile
[INFO] |     +- com.xxx.xxx:xxx:artifact3:zip:100.1.2:compile

你知道是否有可能做到这一点?

提前致谢

标签: maven

解决方案


基本上 Maven 是一个构建工具,而不是一个部署工具。(它有一个deploy阶段,但是除了开发人员本地机器上的本地存储库之外,它还用于将工件部署到远程 Maven 存储库。)

有些插件支持将任意文件部署到任意位置(间接):

一个支持直接部署,但它的 2.0.0 版本已经快两年了,我遇到了一些不适用于最新 Maven 版本的事情。但是,现在我看到两天前有一个 2.0.1

  • Wagon Maven 插件:“使用这个插件来查看和使用 Maven Wagon 在存储库之间传输资源。

    (不要让“存储库之间”混淆您。它支持任意文件和 URL。)


推荐阅读