设置:在 Spring Boot 应用程序中进行Kotlin集成测试。
当我用IntelliJ运行测试时,测试运行良好,但当我尝试用maven运行集成测试时:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.19.1:integration-test (default) on project myapp: Execution default of goal org.apache.maven.plugins:maven-failsafe-plugin:2.19.1:integration-test failed: There was an error in the forked process
[ERROR] java.lang.NoClassDefFoundError: ch/cypherk/myapp/service/CustomerService
[ERROR] at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
[ERROR] at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
[ERROR] at java.base/java.lang.Class.getConstructor0(Class.java:3343)
[ERROR] at java.base/java.lang.Class.getConstructor(Class.java:2152)
[ERROR] at org.apache.maven.surefire.junit.PojoAndJUnit3Checker.isPojoTest(PojoAndJUnit3Checker.java:51)
...
这很烦人,因为我需要竹子来运行这些该死的东西。CustomerService
是一个接口,是的,它是经过编译的,在maven的./target
目录中有一个对应的.class
文件,IntelliJ被设置为使用相同的文件。
不能完全弄清楚为什么这是失败的,并希望与插件的一些帮助。pom.xml
的相关摘录:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- doesn't make a difference if `true` or `false`-->
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*IT*</include>
</includes>
<excludes>
<exclude>**/ui/*</exclude>
</excludes>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
完整pom.xml
:http://freetexthost.com/dbghyawijj
未通过集成测试步骤的完整日志:http://freetexthost.com/gbsmd3mwm2
2条答案
按热度按时间jtoj6r0c1#
面对同样的问题,我们通过添加target/classes作为额外的类路径元素来解决这个问题。它看起来有点脏,但是很有效:
dpiehjr42#
我在将Sping Boot 项目迁移到JDK 17时遇到过这个问题。最后,
pom.xml
的failsafe
部分如下所示: