Maven 4 supports the Maven 3 directory layout, but using module-info.java in the test directory is deprecated. Instead, you should use a module-info-patch.maven file in the test/java directory.
Unlike the Maven 3 approach where the test module-info.java replaces the main one, the module-info-patch.maven file completes the main module-info.class by applying additional compiler arguments (like --patch-module, --add-modules, --add-reads, --add-exports, or --add-opens).
Limitation: Avoid using module names that are single words without a . separator (e.g., foo) if they match a package name, as this can cause ambiguity in the compiler plugin's compatibility layer. Use reverse domain name conventions (e.g., foo.bar).
src
├─ main
│ └─ java
│ ├─ module-info.java
│ └─ org/foo/bar/*.java
├─ test
│ └─ java
│ ├─ module-info-patch.maven (optional)
│ └─ org/foo/bar/*.java
└─ target
└─ classes
└─ org/foo/bar/*.class