[英]Maven Failsafe: NoClassDefFoundError for integration tests
Setup: Kotlin integration tests in a spring boot application.设置:在 Spring Boot 应用程序中进行 Kotlin 集成测试。
Tests work fine when I run them with IntelliJ.当我使用 IntelliJ 运行它们时,测试工作正常。 When I try to run the integration tests with maven, though:
但是,当我尝试使用 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)
...
which is very annoying since I kind of need bamboo to run the darn things.这很烦人,因为我有点需要竹子来运行这些该死的东西。
The CustomerService
is an interface and yes, it is compiled, there's a corresponding .class
file in maven's ./target
directory and IntelliJ is set up to use the same. CustomerService
是一个接口,是的,它是经过编译的,maven 的./target
目录中有一个相应的.class
文件,IntelliJ 设置为使用相同的文件。
Can't quite figure out why this is failing and would appreciate some help with the plugin.无法弄清楚为什么会失败,希望能得到一些关于插件的帮助。
Relavant excerpt from the pom.xml
: 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>
Full pom.xml
: http://freetexthost.com/dbghyawijj完整的
pom.xml
: http : //freetexthost.com/dbghyawijj
Full log of the failing integration test step: http://freetexthost.com/gbsmd3mwm2失败的集成测试步骤的完整日志: http : //freetexthost.com/gbsmd3mwm2
Faced the same problem, sovled it by adding target/classes as additional classpath elements.面对同样的问题,通过添加目标/类作为额外的类路径元素来解决它。 It feels a little bit dirty but works:
感觉有点脏,但有效:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.