【发布时间】:2017-12-12 09:43:32
【问题描述】:
主要目标
要使用命令行在遵循 Maven 的 Standard Directory Layout 的多模块存储库的两个对等模块中编译和运行集成测试:
模块
|_src
|____it 集成测试
|____主要
|____test 单元测试
更新: 结果表明,将 IT 内部测试放在“src / it”文件夹中并不是 Maven 的惯例。 “src / it” 用于 maven-plugin 特定的集成测试。虽然,“src / it”当然可以为 IT 内部测试配置 - 如果您需要配置而不是约定。
简介
我有多模块存储库,其模块继承自父 POM(项目和 Spring 相关)。我无法从“新鲜”mvn clean 开始的命令行编译或运行集成测试,但我可以让 IntelliJ 编译所有源并运行所有测试(作为 Maven 模块)——之后,int 测试也将运行在尽管没有将故障安全绑定到阶段(尽管有点道理),但命令行。如果有的话,我无法确定导致命令行冲突的原因。已经尽我所能搜索了这个问题,而且——是的——我已经尝试了几乎所有我能用谷歌搜索的东西,但无济于事。我的 POM 在这里定义为之前所有尝试更改后的当前状态。
在核心模块上发出mvn help:describe -Dcmd=install 时,它显示故障安全插件(否则在我的 POM 中定义)未绑定到相应的阶段。这可以解释为什么我不能运行集成测试,但不能解释为什么它无法绑定,因为它是在 POM 中定义的。此外,它没有解释为什么 int-test 源没有编译,因为我目前理解 int-test 编译将由编译器插件在 test-compile 阶段下完成,因为在 Maven 生命周期中没有 int-test-compile 阶段.这是正确的还是在integration-test 阶段也这样做了?
Maven 帮助输出
假设我mvn clean install module-parent。那么,
~$: pwd
/repo/module-core
~$: mvn help:describe -Dcmd=install
[INFO] 'install' is a phase corresponding to this plugin:
org.apache.maven.plugins:maven-install-plugin:2.4:install
It is a part of the lifecycle for the POM packaging 'jar'. This lifecycle includes the following phases:
* validate: Not defined
* initialize: Not defined
* generate-sources: Not defined
* process-sources: Not defined
* generate-resources: Not defined
* process-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:resources
* compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
* process-classes: Not defined
* generate-test-sources: Not defined
* process-test-sources: Not defined
* generate-test-resources: Not defined
* process-test-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
* test-compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
* process-test-classes: Not defined
* test: org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
* prepare-package: Not defined
* package: org.apache.maven.plugins:maven-jar-plugin:2.4:jar
* pre-integration-test: Not defined
* integration-test: Not defined
* post-integration-test: Not defined
* verify: Not defined
* install: org.apache.maven.plugins:maven-install-plugin:2.4:install
* deploy: org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
项目结构概览
MainRepo
|_ 模块父级 在下面提供
|____ pom.xml
|
|_ 模块核心 在下面提供
|____ pom.xml
|
|_ 模块后端(春季)
|____ pom.xml
|
|_ 模块前端 (angular2)
|____ pom.xml
模块父/pom.xml
<project>
<!-- ... -->
<groupId>my.apps.module</groupId>
<artifactId>module-parent</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<modules>
<module>../module-core</module>
<module>../module-backend</module>
</modules>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<executions>
<execution>
<id>module-parent-failsafe-it</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>module-parent-failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
模块核心/pom.xml
<project>
<!-- ... -->
<groupId>my.apps.module</groupId>
<artifactId>module-core</artifactId>
<version>0.1.0</version>
<parent>
<groupId>my.apps.module</groupId>
<artifactId>module-parent</artifactId>
<version>0.1.0</version>
</parent>
<!-- ... -->
</project>
其他细节/编辑
还意味着我审查了有效的 POM。看起来不错,但我不是 Maven 专家。 Spring 父 POM || Springs parent 的父 POM 正确设置了 Failsafe 插件,所以 core-module -- 我相信 -- 应该继承自该插件。
【问题讨论】:
标签: compilation maven-3 integration-testing multi-module maven-failsafe-plugin