Maven surefire could not find ForkedBooter class

拈花ヽ惹草 提交于 2019-11-26 23:36:07

To fix it (in 2018), update your openjdk to the latest version, at least 8u191-b12. In case this issue reappears in 2020, it is likely that the default behavior of openjdk was changed, and you will then need to update the maven surefire plugin.

This was a now fixed bug in the openjdk-8 package (behaviour deviates from upstream significantly without need; missing the upstream patch to revert back to disabling a security check) that you just upgraded to. But it is also a bug in the surefire plugin, SUREFIRE-1588, supposedly fixed in surefire 3.0.0-M1: it apparently is using absolute paths in a place where Java will in the future only allow relative path names (and Debian activated the future behavior already).

The package version 8u181-b13-2 states:

  • Apply patches from 8u191-b12 security update.

Note that 191-b12 != 181-b13. The 191-b12 security patches were just out a few days ago, and apparently the maintainers wanted to get them to you fast. Updating completely to 191-b12 will likely need additional testing (well, so should have this upload, apparently).

There had been several workaounds:

  1. You can install the previous package from snapshots.d.o instead. After downgrading, you can forbid the broken version (if you are using aptitude and not apt) using sudo aptitude forbid-version openjdk-8-jre-headless. For regular "apt" I didn't see a similar forbid mechanism, so you would likely need to use apt pinning to prevent this upgrade from being reinstalled (or you just keep on downgrading again, I hope this will be resolved soon).
  2. According to bug tracking, setting the property -Djdk.net.URLClassPath.disableClassPathURLCheck=true with any of the usual methods (e.g., JAVA_FLAGS) should also help. But I have not verified this myself. You can apparently even add the workaround to ~/.m2/settings.xml to get it enabled for all your Maven builds easily.

As you can see, bug tracking works, the issue was narrowed down, and a fixed package is available and a new version of the surefire plugin will come soon!

user3090935

I found this workaround and fixed my tests: configure the maven-surefire-plugin not to use the system classloader.

Markoorn

Set useSystemClassloader to false:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>

If you're not inheriting from a parent which has version defined for you (such as the Spring Boot starter) you'll need to define that as well.

I have another workaround. Set the environment variable _JAVA_OPTIONS. I've used this for our TeamCity build agents and now our builds run fine.

_JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true

I posted a more targeted variant of one of the above workarounds in JIRA. Add to ~/.m2/settings.xml:

<profile>
    <id>SUREFIRE-1588</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
    </properties>
</profile>

I had this issue in my GitLab CI build, which was using maven:3.5.4-jdk-8 Docker image.

Changing it to maven:3.5.4-jdk-8-alpine fixed the problem.

I followed this link https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html and added the below plugin in pom.xml and it worked,

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.1</version>
        <configuration>
          <useSystemClassLoader>false</useSystemClassLoader>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

When using GitLab CI/CD with 3.6.0-jdk-8 image only the property below helped (without modifying pom.xml).

-Dsurefire.useSystemClassLoader=false
Simon Diemert

For those searching for an answer related to Docker Maven: 3.5.x-jdk-8 on GitLab CI, see this GitHub issue.

It appears a 3.5.4-jdk-8 image resulted in upgrade to a minor Java version which somehow affects Surefire's forking mechanism.

Rolling back to 3.5.3-jdk-8 image fixed this for me on my GitLab CI server building Java 1.8 code with Surefire 2.20.1.

farid g.

The suggestion above to set the property "-Djdk.net.URLClassPath.disableClassPathURLCheck=true" did NOT work for me, but setting the following does work OK:

-DforkCount=0

For Ubuntu: Install the latest version, it has this bug fixed

sudo apt-get update ; sudo apt-get dist-upgrade -y

Install the last working version (without security patches) without the bug.

sudo apt-get install openjdk-8-jdk-headless=8u181-b13-1 openjdk-8-jdk=8u181-b13-1  openjdk-8-jre=8u181-b13-1  openjdk-8-jre-headless=8u181-b13-1 openjdk-8-source=8u181-b13-1

If you missed that version, use the version before that:

sudo apt-get install openjdk-8-jdk-headless=8u162-b12-1 openjdk-8-jdk=8u162-b12-1  openjdk-8-jre=8u162-b12-1  openjdk-8-jre-headless=8u162-b12-1 openjdk-8-source=8u162-b12-1

Then use either pinning or watch out that you won't install the broken version.

Using -Djdk.net.URLClassPath.disableClassPathURLCheck=true didn't work for me wherever I had put that configuration. Somewhere in my integration-tests it always exited without the old Java version.

As mentioned by Erich it's a bug in the Debian package being too strict 911925 and the Surefire-plugin not acting according to the new rules SUREFIRE-1588.

I recently setup maven job on Jenkins and got stuck into the same problem. I took the suggestion to modify the JAVA env variable and confirm the issue resolved. This is how I tested.

Becomes "jenkins" user and change folder to workspace project name that you setup for the job.

 $ _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true mvn clean install -U

 $ lsb_release -rd
 Description:   Ubuntu 16.04.5 LTS
 Release:   16.04

 $ mvn -v
 Apache Maven 3.3.9
 Maven home: /usr/share/maven
 Java version: 1.8.0_181, vendor: Oracle Corporation
 Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
 Default locale: en_US, platform encoding: UTF-8
 OS name: "linux", version: "4.4.0-131-generic", arch: "amd64", family: "unix"
jumpnett

I uninstalled the JDK that comes in the repositories:

$ sudo apt purge openjdk-8-jdk

$ sudo apt autoremove

Then I deleted the JAVA_HOME environment variable. Mine was set in my .bashrc.

Then I reinstalled it through SDKMAN:

$ sdk install java 8.0.181-zulu

From their site:

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates.

To see other versions of the JDK to install, use:

$ sdk list java

I was facing the same issue with gitlab ci, changing maven image from maven:3-jdk-8 to maven:3.6.0-jdk-8-alpine seems to fix the issue. Btw I also tested with maven:3.6.0-jdk-8 but it didn't work neither.

I've added dependency to junit-jupiter-engine, and it worked.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.4.0</version>
        </dependency>
    </dependencies>
</plugin>
amdev

If like me you have issues in your pipeline (for me it's in GitLab, but whatever) and if you are using a Maven JDK 8 Docker image.

You can replace

image: maven:3.5.4-jdk-8

by the last working build

image: maven@sha256:b37da91062d450f3c11c619187f0207bbb497fc89d265a46bbc6dc5f17c02a2b
sarir

I am used as this as workaround to stop the compilation and execution of test files:

-Dmaven.test.skip=true with maven
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!