The existing "guesswork" code should be replaced with proper support, this "experiment" (w/ some PoC code) will aim to achieve that.
To achieve the goal, several aspects of Maven (core and plugins) will need changes. The goal of this experiment is to produce a "demo", but not to produce code that may be used as-is, the goal of this experiment is NOT to produce production ready code. Most probably will have more hacks than anticipated (at least this is what I envision).
Dependency types
New types with existing "jar" present just for reference.
name | extension | classifier | [flags] | explanation |
---|---|---|---|---|
jar | jar | - | [CP] | same as today, added to classpath |
module | jar | - | [MP] | a JPMS module, added to modulepath |
java-agent | jar | - | [AG] | ? |
annotation-processor | jar | - | [AP] | not on classpath/modulepath, m-compiler-p handles it |
doclet | jar | - | [DOC] | not on classpath/modulepath, m-javadoc-p handles it |
fatjar | jar | - | [ID,CP] | new type to express "self contained" jar added to classpath |
fatmodule | jar | - | [ID,MP] | new type to express "self contained" module added to modulepath |
Flags:
- CP - added to classpath
- MP - added to modulepath
- AG - agent (do whatever needed with it) -> ?
- AP - annotation processor (do whatever needed with it) -> m-compiler-p handles it
- DOC - doclet (do whatever neede with it) -> m-javadoc-p handles it
- ID - includes dependencies
Note: from Resolver perspective only the ID flag makes sense (so should be defined in resolver, presence of this flag effectivel stops collection), while all the other flags are "Maven customizations", have no meaning for Resolver.
Packaging
packaging=module
Pretty much same as today "jar" packaging, but
In "validate" phase:
- enforce Java9+
- enforce only "module" type of dependencies present in some (which? "compile"+"runtime"+"provided") scopes
- having "test" scoped "jar" type of dependency is okay?
- forbid sytem scope totally?
In "package" phase:
- enforce presence of module descriptor?
- validate module descriptor?
- etc
The output of this packaging would be artifactId-version.jar
(yes, same as for packaging "jar"), that still can be consumed downstream either as type=jar or type=module, as use case requires.
Progress
The modified Maven is here: https://github.com/cstamas/maven/tree/module-experiment
The experimental build project (buildable with modified maven ONLY) is here: https://github.com/cstamas/maven4-jpms-experiment/tree/main
Related documents:
- gist listing needed artifact types and packaging https://gist.github.com/cstamas/4e9bcbef25ce912a90ad1e127b0c5db8