How to compile test code in a modular project?
Till Brychcy
register.jigsaw at brychcy.de
Thu Nov 9 21:05:03 UTC 2017
> Am 09.11.2017 um 09:29 schrieb Alan Bateman <Alan.Bateman at oracle.com>:
>
> Yes, --patch-module is needed to compile the tests "as if" they are part of the module, e.g.
>
> javac --module-path classes:junit.jar --patch-module m=src/test/java --add-reads m=junit -d test-classes \
> src/test/java/p1/P1Test.java
>
Thanks a lot, Alan!
The surprise for me was that --patch-module is used for source folders, too. I thought it was only for binaries.
But I noted I also have to add "--add-modules=junit" or the "--add-reads m=junit" will give an error that module junit cannot be found.
So the command has to be:
javac -d target/test-classes --patch-module m=src/test/java --module-path target/classes:junit-4.8.2.jar --add-modules=junit --add-reads m=junit src/test/java/p1/P1Test.java
I’m not sure if that is a bug or a feature. BTW, I noted that "javac -help" doesn’t mention --patch-module and --add-reads at all (only --add-modules)
More information about the jigsaw-dev
mailing list