ascheman opened a new pull request, #996:
URL: https://github.com/apache/maven-enforcer/pull/996
Implements the three deterministic Java module rules proposed in #995.
## Rules
- **`requireExplicitModules`** — fails a project that compiles classes but
has no `module-info.class`, so an artifact never silently resolves as an
*automatic module*.
- **`requireMinimalExports`** — fails a module that `exports` an
internal/impl package (configurable `internalPackagePattern`, `allowedExports`
whitelist, `ignoreQualifiedExports`).
- **`banUnjustifiedOpens`** — fails an unqualified `opens` (or an `open
module`); qualified `opens … to` and an `allowedOpens` whitelist pass.
Each reads the compiled `module-info.class`, so its `enforce` execution must
run **after compilation** (e.g. bound to `process-classes`). They support both
the classic layout (one `module-info.class` in the output directory) and the
**Maven 4 module source hierarchy** (POM model 4.1.0), where one project
compiles several modules, each to
`${project.build.outputDirectory}/<module-name>/`.
## `module-info` reader — design note
The rules read `module-info.class` through
`java.lang.module.ModuleDescriptor`, accessed **reflectively**. The plugin
compiles with `--release 8` and so cannot reference the Java 9
`ModuleDescriptor` API directly. The obvious alternative — a multi-release JAR
overlay compiled for Java 9 — is deliberately avoided: MRJAR support in Maven 3
is incomplete and can produce invalid JARs (cf. MNG-6892 / MNG-6293,
`maven-jar-plugin#484`), and is only cleanly solved in Maven 4. Reflection
keeps the rules usable on **Maven 3 with a Java 8 baseline**: the API is
present at runtime whenever a `module-info.class` exists (such a project is
necessarily built on Java 9+), and the rules do nothing when there is no
descriptor. The reader also fails with a **clear diagnostic** — rather than
silently — when a `module-info.class` is a newer class-file version than the
JVM running the build.
## Tests
- Unit tests for the reader and each rule (guarded to Java 9+; ASM is used
in **test scope only** to generate `module-info.class` fixtures — production
stays dependency-free).
- ITs under `maven-enforcer-plugin/src/it/projects/`: four classic
single-module (one pass, three fail) plus two Maven 4 module-source-hierarchy
(pass/fail), gated by JDK / Maven version so they skip cleanly on older
toolchains.
- Site pages for the three rules, listed in the built-in rules index.
A follow-up rule for split-package detection across the module path is
planned separately.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]