https://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html
我有一个项目,包含2个模块。
[Parent]
|-pom.xml
| [SpringBoot2App]
| |-pom.xml
| [test]
| |-pom.xml (start goal here!)
我想在另一个模块中运行集成测试(使用Maven Failsafe插件)。
是否可以配置Spring Boot Maven插件,在父模块的集成测试期间启动/停止子模块?
我尝试过类似以下的一些操作,但没有成功:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.SimpleServiceApplication</mainClass>
<classesDirectory>../SpringBoot2App/target/classes</classesDirectory>
<folders>
<param>../SpringBoot2App/target/test-classes</param>
</folders>
</configuration>
<executions>
<execution>
<goals>
<goal>start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
</executions>
</plugin>
不起作用。
我也尝试了在阅读插件的超类源代码https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java后添加“project”参数。
<configuration>
<mainClass>com.SimpleServiceApplication</mainClass>
<project>${project.parent.collectedProjects[0]}</project>
</configuration>
这指的是正确的项目,但调试显示也不起作用。
请不要评论[0],我知道[0]不干净,并且是一种耦合,需要直接了解父pom模块排序的知识。
我在org/springframework/boot/SpringApplication上得到了java.lang.NoClassDefFoundError错误。
我将starter-web项目添加到测试pom.xml中,结果相同。