Hi Jochen, Martin, Thorsten, (and Mirko),
following up on this thread: We ran into the same challenges when trying to get
modular whitebox testing working with Maven 4's Module Source Hierarchy and
module-info-patch.maven.
The short version: it is possible today with surefire 3.5.5, but requires
verbose manual configuration (classesDirectory, testClassesDirectory,
useModulePath, argLine), and the workaround only works for a single Java module
— it does not scale to projects with multiple modules.
We created a proof-of-concept patch for surefire 3.6.0-SNAPSHOT that adds
native support for Maven 4's nested class layout and the compiler-generated
module-info-patch.args file. With the patch, mvn test works without any
surefire configuration.
The issue is tracked at https://github.com/apache/maven-surefire/issues/3345 —
it includes a working example and references to related issues.
For anyone interested in the current workaround or the example project:
https://github.com/aschemaven/java9-jigsaw-examples/tree/feature/surefire-whitebox/jigsaw-examples/example_test/m4
Gerd
> On 10. Apr 2026, at 08:56, Thorsten Heit <[email protected]> wrote:
>
> Hi Jochen,
>
>> It is not possible to access package-private classes or members from another
>> module, except by using the `--patch-module` option. But that option should
>> be used only for testing purposes or as temporary patches, not in production.
>> An alternative is to put the classes and methods that you want to share as
>> public members in another package, then export that package using qualified
>> export. For example, if a module A provides a package `foo` and if you want
>> that only module A and B can access that package `foo`, the
>> `module-info.java` file of module A can contains the following declaration:
>> `export foo to B;`. It is the way to allow access to internal classes to
>> only the modules of your choice.
>> It is not always easy to do Java modules in Maven 3, because Maven 3 tries
>> to make automatic choices. This is nice when the choices are what we want,
>> but it becomes difficult otherwise. Maven 4 tries to give control back to
>> developers, but the work is not finished. In particular, while the Maven
>> Compiler plugin is ready, we have not yet updated the Maven Surefire plugin.
>
> Apart from all of the above a good read if you don't already know:
>
> https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world.html
>
>
> HTH
>
> Thorsten
> <OpenPGP_0x5A54BBB878225E08.asc>
--
Gerd Aschemann --- Veröffentlichen heißt Verändern (Carmen Thomas)
+49/173/3264070 -- [email protected] -- http://www.aschemann.net