Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot fails to run maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter

Running maven (3.5.2) build of a Spring Boot 2.0.2.RELEASE applicaton (generated by web initialiser with web dependencies) fails executing the maven-surefire-plugin saying just:

Error: Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter

Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.booter.ForkedBooter

Why is this happening? Is it a problem in boot + surefire integration = a bug?

For reference, the dependencies that seem relevant are:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/>
</parent>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
</dependency>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
like image 329
jediz Avatar asked Jun 02 '18 22:06

jediz


3 Answers

Workaround for the issue was to override Spring Boot's maven-surefire-plugin definition and set useSystemClassLoader to false. Read Surefire docs for more details

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>
like image 64
jediz Avatar answered Nov 15 '22 01:11

jediz


The <useSystemClassLoader>false</useSystemClassLoader> solution provideded by jediz did allow my surefire tests to run, but broke class loading in some of my Spring Boot integration tests.

The following maven-surefire-plugin configuration worked for me:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
    </configuration>
</plugin>
like image 21
Andreas Presthammer Avatar answered Nov 15 '22 02:11

Andreas Presthammer


This is due to a known bug in the Maven Surefire plugin. It was fixed in version 3.0.0-M1, which was released in November 2018. So the simplest and most reliable fix is to upgrade which version of the plugin you use.

Updating the maven-surefire-plugin from 2.12.4 to 3.0.0-M1 worked for me. The project did not explicitly use the plugin, so I had to add a new plugin dependency.

<plugins>
   ...
   <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-M1</version>
   </plugin>
   ...
</plugins>
like image 14
rvange Avatar answered Nov 15 '22 02:11

rvange