apache / apache/maven-surefire

Offline Build for JUnit 5 Project Fails - Missing `surefire-junit-platform:jar` dependency

Open
#3,248 2 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

### Affected version

3.5.4

### Bug description

# Description

I have a project that is set up to use JUnit 5 and the Maven Surefire plugin, per the [official documentation](https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html).
When trying to simulate a pre-fetched "offline build" workflow, builds that run tests fail because the Surefire plugin attempts to dynamically download the `surefire-junit-platform` JAR as a dependency.

# Expected Behavior

Surefire plugin declares all necessary dependencies for `go-offline` (and similar tools/plugins) to work, and/or the documentation provides necessary instructions for all dependencies to be declared up front.

# Actual Behavior

Build fails:

```sh
$ mvn clean package -o -Dmaven.repo.local=tmp-local
....
[INFO] --- surefire:3.5.4:test (default-test) @ single-module ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[WARNING] The POM for org.apache.maven.surefire:surefire-junit-platform:jar:3.5.4 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.748 s
[INFO] Finished at: 2026-01-28T15:20:37-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.4:test (default-test) on project single-module: The following artifacts could not be resolved: org.apache.maven.surefire:surefire-junit-platform:jar:3.5.4 (absent): Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven.surefire:surefire-junit-platform:jar:3.5.4 has not been downloaded from it before. -> [Help 1]
```

# Reproducer

Using the "Hello World" example [here](https://github.com/adambkaplan/hermetoproject-integration-tests/tree/maven/single-module), run the following:

```sh
$ mvn org.apache.maven.plugins:maven-dependency-plugin:3.9.0:go-offline -Dmaven.repo.local=tmp-local
...
$ mvn clean package -o -Dmaven.repo.local=tmp-local
```

# Workaround

No clear workaround - adding the missing JAR as a plugin dependency leads to "classpath hell."

`pom.xml`:

```xml


org.junit.jupiter
junit-jupiter-engine
5.11.0
test

...

org.apache.maven.plugins
maven-surefire-plugin
3.5.4


org.apache.maven.surefire
surefire-junit-platform
3.5.4



```

Result:

```sh
[ERROR] There was an error in the forked process
[ERROR] org.junit.platform.commons.JUnitException: The wrapped NoClassDefFoundError is likely caused by the versions of JUnit jars on the classpath/module path not being properly aligned.
[ERROR] Please ensure consistent versions are used (see https://junit.org/junit5/docs/5.12.1/user-guide/#dependency-metadata).
[ERROR] The following conflicting versions were detected:
[ERROR] - org.junit.platform.commons: 1.11.0
[ERROR] - org.junit.platform.engine: 1.11.0
[ERROR] - org.junit.platform.launcher: 1.12.1
```

Contributor guide

Open the contributing guide

Research direction

Start with the pom.xml and reproduce the issue using the documented go-offline command followed by mvn clean package -o with the temporary local repository. Trace how the Maven Surefire plugin resolves surefire-junit-platform:3.5.4 and compare that with the reported JUnit version conflict. Done means the reproducer completes an offline build without the workaround or classpath conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.