[SUREFIRE-2190] Fix module dependencies for compile only dependencies #668
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Include all modules on the module path to the root modules. This fixes
test code that uses dependencies that are declared as optional
(
require static
) for the main artifact to access these dependencies.maven surefire plugin struggles with optional dependencies for the main artifact and test code.
Check out the test repo at https://github.com/hgschmie/msurefire2190
This repo contains three artifacts with identical code:
requires
) dependency on jakarta.annotation.requires static
) dependency on jakarta annotations.The code and its test classes are otherwise identical.
Running
mvn -DskipTests clean install
builds all three modules and the test code.Running
mvn surefire:test
passes the tests in the first two modules but fails in the third.The surefire plugin, when it executes tests using JPMS adds all
referenced modules to the module path (in this case the module under
test itself and the jakarta.annotations-api jar). It then adds the
main module using
--add-modules
and patches this module with thetest classes (so that the test classes execute as part of the module).
In case of a
requires
relationship, the JVM will find the requiredJPMS module and add it as accessible. This is why the "thing2" tests
pass.
In case of a
requires static
relationship, the JVM will not add themodule transitively as it is considered a compilation-only
dependency. For the code under test to be able to access the classes
from
jakarta.annotation
, they must be declared as a module. However,the test code only adds the module under test with
--add-modules
.The fix for this is pretty simple but must be done in the surefire
plugin. Instead of adding
--add-modules <... module id under test..>
,it needs to add
--add-modules ALL-MODULE-PATH
. Which iscorrect, because the code is not looking for compile time only
dependencies but actual runtime dependencies where the code under
execution may also need to access optional runtime dependencies (see
https://nipafx.dev/java-modules-optional-dependencies/ for a slightly
longer explanation).
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
SUREFIRE-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean install
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean install
).To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.