我有一个包含许多模块的 Maven POM 项目。
其中一个是其他一些模块使用的 REST Web 服务。 该模块是一个独立的可执行文件。
我想要实现的是让 Web 服务在所有其他模块之前构建和运行。
我知道只需更改 pom 文件中模块的顺序,我就可以让模块先于其他模块构建,但是如何在构建其余模块之前运行它?
我需要运行它,以便执行其余模块中包含的一系列测试。
我尝试实现这种功能的原因是因为我最终要做的是在 Jenkins 上正确构建和测试项目。
最佳答案
I understand that just by changing the order of the modules in the pom file I can get the module to build before the others, but how do I run it before building the rest of them?
模块的顺序将不一定按该顺序构建它们。如果一个模块依赖于另一个模块,那么您必须通过 <dependency>
来处理它。在依赖项目的pom中。
要回答您的问题,请先构建 REST 服务模块并将其部署到您的服务器/容器。在多模块项目中运行类似 mvn somegoal
的命令将运行 somegoal
在所有模块上。
要在模块上运行不同的目标,请分两步尝试
mvn -pl module1 somegoal
mvn -pl module2 someothergoal
在您的项目中,它们将采用以下形式
mvn -pl RESTModule deploy
其次是通常
用于运行其他模块测试的 mvn 命令。也请记住这些的 -pl 选项。
编辑:在查看了您评论中的要求后,我尝试了另一种解决方案。也可能对你有用。将 maven-deploy-plugin 添加到 REST 模块的 pom 并将其绑定(bind)到一个阶段,这样只有 RESTModule 项目部署 Artifact 而不部署其他项目(因为他们的 pom 中没有这样的插件)。要添加的片段。
`
<project>
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>MyProjId</id>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
<distributionManagement>
<repository>
<id>my-repository</id>
<url>http://path/to/your/repo</url>
</repository>
</distributionManagement>
</project>
并在 jenkins 中使用父 pom 运行项目。
关于java - Maven:如何在多模块项目中构建其他模块之前运行模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41720390/