Re: Surefire and Java Modules

Gerd Aschemann <[email protected]> Mon, 13 Apr 2026 23:32:04 +0200
Newsgroups gmane.comp.jakarta.turbine.maven.user
Message-ID <[email protected]>
--Apple-Mail=_6BF89049-F0D6-41E2-BD98-D8372D36752C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hi Jochen, Martin, Thorsten, (and Mirko),
                                                                         =
                                                                         =
                                                                         =
                                                                         =
               =20
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.
                                                                         =
                                                                         =
                                                                         =
                                                                         =
               =20
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 =E2=80=94 it does not scale to projects =
with multiple modules.                           =20
                                                                         =
                                                                         =
                                                                         =
                                                                         =
               =20
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.                                =
                            =20
                                                           =20
The issue is tracked at =
https://github.com/apache/maven-surefire/issues/3345 =E2=80=94 it =
includes a working example and references to related issues.             =
                                                                         =
                                                                         =
    =20
                                                           =20
For anyone interested in the current workaround or the example project:  =
                                                                         =
                                                                         =
                                                                         =
             =20
=
https://github.com/aschemaven/java9-jigsaw-examples/tree/feature/surefire-=
whitebox/jigsaw-examples/example_test/m4
                                                                         =
                                                                         =
                                                                         =
                                                                         =
               =20
  Gerd                                                     =20

> On 10. Apr 2026, at 08:56, Thorsten Heit <[email protected]> wrote:
>=20
> Hi Jochen,
>=20
>> 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.
>=20
> Apart from all of the above a good read if you don't already know:
>=20
> =
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world.ht=
ml
>=20
>=20
> HTH
>=20
> Thorsten
> <OpenPGP_0x5A54BBB878225E08.asc>

--
Gerd Aschemann --- Ver=C3=B6ffentlichen hei=C3=9Ft Ver=C3=A4ndern =
(Carmen Thomas)
+49/173/3264070 -- [email protected] -- http://www.aschemann.net


--Apple-Mail=_6BF89049-F0D6-41E2-BD98-D8372D36752C--