Surefire "error in the forked process" in CI - Fix the Test JVM
Surefire runs tests in a forked JVM. "There was an error in the forked process" means that JVM failed before tests could report - a malformed argLine, a missing class on the test classpath, or a Java agent that could not attach.
What this error means
The test phase fails with There was an error in the forked process followed by a concrete cause like Error: Could not find or load main class, a bad -javaagent, or an Unrecognized VM option. No test results are produced.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test
(default-test) on project app: There was an error in the forked process
[ERROR] Unrecognized VM option 'UseSerialGCC'Common causes
Malformed argLine or VM option
A typo in argLine (e.g. a bad GC flag), or a duplicated/empty @{argLine} placeholder from JaCoCo, makes the forked JVM refuse to start.
A Java agent or missing class breaks startup
A -javaagent jar that does not exist, or a missing test-classpath class needed during bootstrap, kills the fork before tests run.
How to fix it
Validate and fix the forked JVM options
Correct argLine and make sure the JaCoCo placeholder is preserved.
<configuration>
<!-- preserve @{argLine} so JaCoCo's agent flags survive -->
<argLine>@{argLine} -Xmx1g -XX:+UseG1GC</argLine>
</configuration>Reproduce the fork to see the real error
- Run
mvn -X testto print the exact forked-JVM command line and its first error. - Check every
-javaagent/-Dflag points at a real path/value. - Temporarily set
<forkCount>0</forkCount>to run in-process and surface the underlying cause.
How to prevent it
- Keep
@{argLine}intact for coverage agents, validate VM options, and pin agent jar paths so the forked JVM always starts.