我必须从远程位置解压一些依赖项并在本地安装它们。
我成功地获取了它们(使用 antrun 插件)并安装了它们(使用了 install 插件)
但是,如果我将它们定义为依赖项 (<dependency>..</dependency>
),maven 会首先尝试解析它们,只有在成功后,才会继续执行 antrun 并安装。
我还尝试了 build-helper-plugin 及其附加 Artifact ,但它什么也没做(它甚至没有将 Artifact 添加到最终的 war 文件中)
那么,如何在 maven 尝试解决依赖关系之前运行我的执行?
最佳答案
有趣的问题!一种尝试(也许)实现这一目标是使用多模块项目设置。
在父项目中获取并安装您的依赖项,并在子模块中使用它们。我这样测试了我的假设:
父 pom.xml
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>foo.bar.parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>foo.bar.child</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<target>
<echo
message="Hello world!" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
模块 pom.xml
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>foo.bar.child</artifactId>
<version>1.0.0</version>
<parent>
<groupId>foo.bar</groupId>
<artifactId>foo.bar.parent</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<artifactId>can.not</artifactId>
<groupId>find.me</groupId>
<version>0.0.0</version>
</dependency>
</dependencies>
</project>
在子模块构建失败(因为缺少依赖项)之前,我从父 pom 构建中获得了“Hello World”输出。如果您实现了在 parent.pom 的构建中提供依赖项,则子模块项目应该是可构建的。
关于java - 有没有办法在 Maven 尝试解决它们之前安装 Maven 依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5951999/