apache / apache/maven-surefire

[SUREFIRE-1501] Optional dependencies not correctly handled with JPMS modules

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

Description

**[Stephen Colebourne](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=scolebourne@joda.org)** opened **[SUREFIRE-1501](https://issues.apache.org/jira/browse/SUREFIRE-1501?redirect=false)** and commented

Attached is a pointlessly simple project for Java 9. The module-info declares an _optional_ dependency on Google Guava (an automatic module) using _requires static_. This optionality is reflected in the pom.xml, where the dependency is marked as optional.

It fails in surefire with JAVA_HOME=jdk9. The reason seems to be that although the Guava jar file is added to the modulepath, it is not referenced using --add-modules. As such, the module graph builder never pulls it in, despite it being on the modulepath. (Optional dependencies need to be directly added using --add-modules if in Maven's dependency graph)

Adding the --add-modules to the `argLine` parameter solves the problem, but this is a bug because the surefire plugin should handle the situation without manually adding it.

NOTE! The attachment has the --add-modules manually added to the pom.xml. Remove it to see the bug.

---

**Affects:** 2.21.0

**Attachments:**
- [maven-issue1.zip](https://issues.apache.org/jira/secure/attachment/12914716/maven-issue1.zip) (_4.03 kB_)

1 votes, 4 watchers

Contributor guide

Open the contributing guide

Research direction

Start with the attached maven-issue1.zip and its pom.xml, removing the manually added --add-modules from argLine. Reproduce under JDK 9 and trace how Surefire constructs the module path and module arguments; done means the optional Guava module runs without manual --add-modules.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.