【发布时间】:2021-05-12 02:34:27
【问题描述】:
我一直在尝试将我们的集成测试转换为使用 Maven Exec 插件来启动服务器,但它只会在集成测试执行后启动 HTTP 服务器,即使我指定了 pre-integration-test。
问题
第一季度。有没有其他方法可以让集成测试在之后开始?
第二季度。有没有办法让集成阶段等待服务器启动?
第三季度。 Maven Exec 和 Bazaar Maven Exec 插件有什么区别?
注意:这之前使用 bazaar maven exec plugin 有效,但现在已损坏,似乎无法让它在 Jenkins 上为 JDK 11.0.9 恢复工作。
下面是我们 POM 的 sn-p,我们有各种其他插件创建 jar 并启动 MockServer。
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>exec</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
<executable>java</executable>
<commandlineArgs>-Dserver.port=8089 -jar /gitRepos/public-api/target/api-jar-with-dependencies.jar</commandlineArgs>
<async>true</async>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<excludedGroups>${it.excluded}</excludedGroups>
<argLine>--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED</argLine>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
</plugin>
</plugins>
<!-- this what was previously working. -->
<!-- <plugin>-->
<!-- <groupId>com.bazaarvoice.maven.plugins</groupId>-->
<!-- <artifactId>process-exec-maven-plugin</artifactId>-->
<!-- <version>0.9</version>-->
<!-- <configuration>-->
<!-- <processLogFile>${project.build.directory}/my-log.log</processLogFile>-->
<!-- </configuration>-->
<!-- </plugin>-->
对我来说奇怪的是在集成测试之后启动的 HTTP 服务器,就像其他插件阻止服务器启动一样。请参阅下面的日志。
[DEBUG] Freed 4 thread-local buffer(s) from thread: nioEventLoopGroup-3-20
[DEBUG] Freed 4 thread-local buffer(s) from thread: nioEventLoopGroup-3-19
[DEBUG] Freed 5 thread-local buffer(s) from thread: nioEventLoopGroup-3-28
[INFO] [main] 13:13:37.594 [main] INFO c.i.p.s.Server - Grizzly ThreadPool for listener grizzly set to 24 worker threads.
[INFO] [main] 13:13:37.724 [main] INFO o.g.g.http.server.NetworkListener - Started listener bound to [0.0.0.0:8089]
[INFO] [main] 13:13:37.726 [main] INFO o.g.grizzly.http.server.HttpServer - [HttpServer] Started.
【问题讨论】:
-
首先排除简单的事情...根据exec-maven-plugin docs
mainClass是java目标的configuration中的有效元素,而不是您正在使用的exec目标.在我们深入研究您的(实际)问题之前,您能否先尝试解决此问题? -
@mle 抱歉,这肯定是尝试另一个配置时留下的,它已被注释掉,我可以确认存在相同的行为。
标签: maven maven-failsafe-plugin exec-maven-plugin