[
https://issues.apache.org/jira/browse/SUREFIRE-1563?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16596608#comment-16596608
]
Christian Stein commented on SUREFIRE-1563:
-------------------------------------------
All modules you want to use at runtime need to visible at resolution time.
Using `--show-module-resolution` to debug is good way to see what is resolved
at the startup of the Java module system.
As the `static` modifiers suppresses the _read edge addition_ at startup, you
need to include it manually via `--add-modules=org.slf4j`. You may use the
short-cut `--add-modules=ALL-MODULE-PATH` to force all modules available on the
module-path to be resolved. The latter did the trick for me from the console –
i don't know how to configure Surefire to add additional Java options at
runtime.
*OR*
You duplicate the _main_ module descriptor and maintain a _test_ module
descriptor that declares all required modules at test-runtime. Then, use the
[https://github.com/sormuras/junit-platform-maven-plugin] that supports
"modular whitebox testing mode" out of the box. [~rfscholte], this issue
demonstrates the need for a test-scoped module descriptor. You don't want users
to mess with additional Java command line options and using the "load all
modules with --add-modules=ALL-MODULE-PATH" a too broad band-aid. And having a
test launcher framework guess the correct root modules from the POM is brittle
at best.
The test-scoped `module-info.java` could look like this:
{{// Same(!) name as "main" module descriptor. Most IDEs will choke, though.}}
{{// You may "open" the module here to allow reflective access of testing
frameworks. Not needed here, though.}}
{{module org.eclipse.jetty.util.logging {}}
{{ // copied from "main" module descriptor }}
{{ exports org.eclipse.jetty.util.logging;}}
{{ // copied from "main" module descriptor }}
{{ requires org.slf4j; // not(!) static here, let the module system resolve
it}}
{{ // test-only modules}}
{{ requires junit; // JUnit 4 API for testing}}
{{ requires org.apache.logging.log4j; // needed by transitive dependency}}
{{}}}
> NoClassDefFoundError for JPMS modules with "require static"
> -----------------------------------------------------------
>
> Key: SUREFIRE-1563
> URL: https://issues.apache.org/jira/browse/SUREFIRE-1563
> Project: Maven Surefire
> Issue Type: Bug
> Components: Maven Surefire Plugin
> Affects Versions: 2.22.0
> Reporter: Simone Bordet
> Priority: Major
> Attachments: maven-jpms.tgz
>
>
> When a Maven module has a {{module-info.java}} that contains a {{requires
> static}}, Surefire throws {{NoClassDefFoundError}} when running the tests for
> that Maven module.
> If the dependency is declared only as {{required}} (no {{static}}), then the
> tests run fine.
> Attached a reproducible project.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)