You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "ascheman (via GitHub)" <gi...@apache.org> on 2026/04/13 21:21:43 UTC
[I] Support Maven 4 Module Source Hierarchy and module-info-patch.args for modular whitebox testing [maven-surefire]
ascheman opened a new issue, #3345:
URL: https://github.com/apache/maven-surefire/issues/3345
## Summary
When using Maven 4's Module Source Hierarchy (modular source declarations in the POM) and `module-info-patch.maven` for whitebox testing of Java modules, surefire requires manual workarounds (`classesDirectory`, `testClassesDirectory`, `useModulePath`, `argLine`) that should not be necessary.
## Problem
Maven 4 with maven-compiler-plugin 4.0.0-beta-4 compiles modular sources to a nested layout:
- `target/classes/<module-name>/` instead of `target/classes/`
- `target/test-classes/<module-name>/` instead of `target/test-classes/`
Additionally, maven-compiler-plugin generates `target/test-classes/META-INF/maven/module-info-patch.args` from `module-info-patch.maven`, containing `--add-exports` and `--add-opens` directives for test execution.
Surefire 3.5.5 / 3.6.0-SNAPSHOT does not handle either:
1. **Module detection** — `findModuleDescriptor()` looks for `module-info.class` directly in `target/classes/` but misses the nested `target/classes/<module-name>/module-info.class`
2. **Test class scanning** — `DirectoryScanner` scans `target/test-classes/` and finds `<module-name>/pkg/Test.class`, interpreting the module name as a package prefix
3. **module-info-patch.args** — surefire auto-generates `--add-opens` and `--add-reads` but does not read the compiler-generated args file containing `--add-exports` directives from `module-info-patch.maven`
## Current workaround (surefire 3.5.5)
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.5</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}/modfib</classesDirectory>
<testClassesDirectory>${project.build.testOutputDirectory}/modfib</testClassesDirectory>
<useModulePath>true</useModulePath>
<argLine>--add-reads modfib=ALL-UNNAMED --add-exports modfib/pkgfib.internal=ALL-UNNAMED
--add-opens modfib/pkgfib=ALL-UNNAMED --add-opens modfib/pkgfib.internal=ALL-UNNAMED</argLine>
</configuration>
</plugin>
```
**Note:** This workaround hardcodes a single module name in `classesDirectory`, `testClassesDirectory`, and `argLine`. It does not scale to projects with multiple Java modules — each would need its own configuration, which is not possible with a single surefire execution.
## Expected behavior
With Maven 4 Module Source Hierarchy and a `module-info-patch.maven` file, `mvn test` should work without any explicit surefire configuration beyond specifying the plugin version.
## Working example
- Repository: https://github.com/aschemaven/java9-jigsaw-examples/tree/feature/surefire-whitebox/jigsaw-examples/example_test/m4
- First commit: workaround with surefire 3.5.5
- Second commit: zero-config with a locally patched surefire 3.6.0-SNAPSHOT (proof-of-concept, all 838 surefire-common tests passing)
## Related issues
- #3090 (SUREFIRE-1755) — Put dependencies from module-info in test sources on module path
- #3088 (SUREFIRE-1765) — target/test-classes should not be added to classpath when tests run on modulepath using patch-module
- #3040 (SUREFIRE-1811) — Add resources to test module
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Support Maven 4 Module Source Hierarchy and module-info-patch.args for modular whitebox testing [maven-surefire]
Posted by "ascheman (via GitHub)" <gi...@apache.org>.
ascheman commented on issue #3345:
URL: https://github.com/apache/maven-surefire/issues/3345#issuecomment-4305499336
> > Thanks for looking at this! Do we have a link to the patch for Surefire 3.6.0-SNAPSHOT?
>
> I will raise a PR soon but first wanted to do a little more testing.
Intermediate status message, @desruisseaux: I wanted to add respective ITs which need to run with Maven 4. Unfortunately there is a (larger) number of other ITs which do not yet work with Maven 4. So I first have to investigate this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Support Maven 4 Module Source Hierarchy and module-info-patch.args for modular whitebox testing [maven-surefire]
Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on issue #3345:
URL: https://github.com/apache/maven-surefire/issues/3345#issuecomment-4243765255
Thanks for looking at this! Do we have a link to the patch for Surefire 3.6.0-SNAPSHOT?
On a related topic, now that the JUnit 3 dependency is removed, are we ready to create a 4.0 branch? Or create a 3.x branch are target master as the development branch for 4.0?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Support Maven 4 Module Source Hierarchy and module-info-patch.args for modular whitebox testing [maven-surefire]
Posted by "ascheman (via GitHub)" <gi...@apache.org>.
ascheman commented on issue #3345:
URL: https://github.com/apache/maven-surefire/issues/3345#issuecomment-5011201829
@desruisseaux — the PR is finally up: #3392 implements the Module Source Hierarchy support (nested `target/classes/<module>/` detection, nested test-class scanning, and consumption of the compiler-generated `module-info-patch.args`), including two ITs: the classic `--patch-module` whitebox layout and a model-4.1.0 module source hierarchy fixture with `module-info-patch.maven`.
Compared to the April proof of concept it additionally fixes a latent parser bug — the compiler writes `module-info-patch.args` with option and value on the *same* line, while the PoC assumed the two-line argfile form and could swallow an `--add-exports` directly following a skipped option — and it was verified against Maven 3.9.16, 3.10.0-rc-1, 4.0.0-rc-5 and the current 4.0.x-SNAPSHOT (rc-6 candidate).
Scope of #3392 is one Java module per POM. Support for *several* modules per POM (`<build><sources>` with multiple `<module>` entries) is already implemented on a follow-up branch — verified against a real three-module component (602 tests, zero-config, one surefire execution) — and will arrive as a dedicated issue plus a stacked draft PR shortly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Support Maven 4 Module Source Hierarchy and module-info-patch.args for modular whitebox testing [maven-surefire]
Posted by "ascheman (via GitHub)" <gi...@apache.org>.
ascheman commented on issue #3345:
URL: https://github.com/apache/maven-surefire/issues/3345#issuecomment-4244295562
> Thanks for looking at this! Do we have a link to the patch for Surefire 3.6.0-SNAPSHOT?
I will raise a PR soon but first wanted to do a little more testing.
> On a related topic, now that the JUnit 3 dependency is removed, are we ready to create a 4.0 branch? Or create a 3.x branch are target master as the development branch for 4.0?
-> @olamy?
To implement the feature it should not be necessary to switch to Maven 4 API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org