5

Setup: Kotlin integration tests in a spring boot application.

Tests work fine when I run them with IntelliJ. When I try to run the integration tests with maven, though:

[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.

Can't quite figure out why this is failing and would appreciate some help with the plugin.

Relavant excerpt from the 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

Full log of the failing integration test step: http://freetexthost.com/gbsmd3mwm2

user944849
  • 14,524
  • 2
  • 61
  • 83
User1291
  • 7,664
  • 8
  • 51
  • 108

2 Answers2

6

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>
user3119291
  • 131
  • 2
  • 2
2

I've faced this issue while migrating the Spring Boot project to JDK 17. In the end, the failsafe section of the pom.xml looked like this:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.22.2</version>
    <executions>
      <execution>
        <id>integration-test</id>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>verify</id>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <forkCount>1</forkCount>
      <reuseForks>false</reuseForks>
      <argLine>@{argLine}</argLine>
      <includes>
        <include>**/*IT.java</include>
      </includes>
      <classesDirectory>${project.build.outputDirectory}</classesDirectory>
      <trimStackTrace>false</trimStackTrace>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.22.2</version>
      </dependency>
    </dependencies>
  </plugin>
Andrey Lebedenko
  • 1,850
  • 17
  • 24