Compilation Maven集成测试阶段不绑定到故障保护 主要目标
要使用命令行在多模块存储库的两个对等模块中编译和运行集成测试,请遵循Maven的:Compilation Maven集成测试阶段不绑定到故障保护 主要目标,compilation,maven-3,integration-testing,multi-module,maven-failsafe-plugin,Compilation,Maven 3,Integration Testing,Multi Module,Maven Failsafe Plugin,要使用命令行在多模块存储库的两个对等模块中编译和运行集成测试,请遵循Maven的: 模块 |u src |uuuuuuuuu it集成测试 |uuuuuuu main | uuuu测试单元测试 更新:事实证明,将IT int测试放在“src/IT”文件夹中不是Maven的惯例。“src/it”用于maven插件特定的集成测试。尽管如此,“src/it”当然可以为it int测试进行配置——如果您需要超过约定的配置 简介 我有一个多模块存储库,其模块继承自父POM(项目和Spring相关)。我不能
模块
|u src
|uuuuuuuuu it集成测试
|uuuuuuu main
| uuuu测试单元测试
更新:事实证明,将IT int测试放在“src/IT”文件夹中不是Maven的惯例。“src/it”用于maven插件特定的集成测试。尽管如此,“src/it”当然可以为it int测试进行配置——如果您需要超过约定的配置 简介 我有一个多模块存储库,其模块继承自父POM(项目和Spring相关)。我不能从“fresh”
mvn clean开始从命令行编译或运行集成测试,但我可以让IntelliJ编译所有源代码并运行所有测试(作为Maven模块)——之后,int测试也将在命令行运行,尽管没有将Failsafe绑定到phase(尽管sorta是有意义的)。我无法确定是什么导致了命令行中的冲突,如果有的话。我已经尽我所能搜索了这个问题,而且——是的——我已经尝试了几乎所有我能用谷歌搜索到的东西,但都没有用。我的POM在此定义为所有先前尝试更改后的当前状态
在核心模块上发布mvn帮助:descripe-Dcmd=install
时,它显示故障保护插件(在我的POM中另有定义)未绑定到相应的阶段。这可以解释为什么我不能运行集成测试,但不能解释为什么它不能被绑定,因为它是在POM中定义的。此外,它没有解释为什么int测试源代码没有编译,因为我目前理解int测试编译是由编译器插件在test compile
阶段完成的,因为在Maven生命周期中没有int test compile
阶段。这是正确的还是在集成测试阶段也这样做
Maven帮助输出
假设我mvn干净安装
模块父级。那么
~$: 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
| 下面提供的模块父级
|uuupom.xml
|
| 模块核心如下所示
|uuupom.xml
|
| 模块后端(spring)
|uuupom.xml
|
| 模块前端(角度2)
|uuupom.xml
模块父级/pom.xml
my.apps.module
模块父级
0.1.0
聚甲醛
org.springframework.boot
spring启动程序父级
1.5.3.1发布
../模块核心
../module后端
org.apache.maven.plugins
maven故障保护插件
2.20
模块父级故障保护it
集成测试
集成测试
模块父级故障保护验证
验证
验证
模块core/pom.xml
my.apps.module
模芯
0.1.0
my.apps.module
模块父级
0.1.0
其他详情/编辑
还想提一下,我审查了有效的POM。看起来不错,但我不擅长Maven。Spring parent POM | | Spring parent的父POM正确设置了故障保护插件,所以我认为核心模块应该继承它。我假设故障保护没有出现在中。帮助:描述..
各个阶段旁边是我问题的根源,但事实并非如此(请参阅故障保护不绑定到X或Y的答案)。在两个不同的源位置(src/it和src/test)之间设置两种测试类型(int/unit)是问题所在,在使用Maven时,这似乎是一个常见的配置难题。这是因为它违反了Maven假设项目将如何设置的约定
为了实现使用两个不同的源文件夹进行测试,我找到了[],他演示了[](org.codehaus.mojo:buildhelpermaven-plugin)的使用它使用额外的源代码配置执行,以便在编译期间使用。这解决了上面定义的主要目标,尽管是以一种非常规的方式,但同时也引入了其他问题。或者,使用Maven的约定只需要将集成测试移到“src/test”中每个模块的位置,并可能更新测试名称。我没有遇到这样的额外问题,我发现这是一个更简单的解决方案
解决方案1:常规
将每个模块的集成测试移到“src/test”类路径
为集成测试命名,包括“IT”[]
mvn安装
parent->core->backend模块
解决办法2:非常规
将buildhelpermaven插件添加到moduleparent下的parent pom.xml中
mvn安装
parent->core->backend模块
模块父级/pom.xml:
org.codehaus.mojo
构建助手maven插件
3.0.0
添加集成测试源
生成测试源
添加测试源
src/it/java
添加集成测试资源
<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>
<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>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- ... -->
</plugins>
</build>
<project>
<!-- ... -->
<groupId>single.module.apps</groupId>
<artifactId>lone-module</artifactId>
<version>0.1.0</version>
<dependencies>
<!-- ... -->
</dependencies>
</project>
* integration-test: Not defined
* ...
* verify: Not defined
<project>
<!-- ... -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</project>
[INFO] --- maven-failsafe-plugin:2.20:integration-test (default) @ lone-module ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running ServiceIT
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.388 s - in ServiceIT