-
Notifications
You must be signed in to change notification settings - Fork 179
Build projects that are both multi-module and multi-release. #959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Build projects that are both multi-module and multi-release. #959
Conversation
This pull request partially depends on apache/maven#11118. But it still work without that fix if there is at most one version after the base version. |
I'm not sure who to ask for a review. Maybe @slawekjaranowski ? Keeping in mind that the decision about "Directory layout choice" is probably not too important for now, because most developers will probably not use it before other plugins have been updated. |
This should also relate to the work needed on m-sources-p to better support source files for multi-release jars. |
Why does the m-jar-plugin comes into play here ? AFAIK, it's completely agnostic and simply jars whatever is in the
One of the reason is that the |
When If we want Regarding the JAR plugin, there are two scenarios in the context of JPMS. A key point is that module hierarchy is an optional feature of Java. It is possible to do JPMS with package hierarchy, at the cost of being constrained to a single JPMS module per Maven sub-project. When using package hierarchy, the NOTE: the fact that other plugins such has Surefire and JAR have not yet been updated does not block users from using the JPMS support provided by this pull request and #963. It only blocks the use of module source hierarchy. Other JPMS features are available and can be used now if users stick to package hierarchy.
For a sub-project using package hierarchy, regardless if JPMS or not, yes and it is already the case. For module hierarchy, not as far as I know. But as said above, module hierarchy is optional even for a JPMS project, and will require update in other plugins anyway, regardless the directory layout discussed above. Even for a classical class-path project ignoring all the JPMS stuff, improvement of the Surefire plugin is needed anyway if we want to test any version other than the base version. |
Documentation about this feature has been added in #976, in particular in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR extends the Maven compiler plugin to support projects that are both multi-module and multi-release, previously only one or the other was supported. It also fixes the separation of javac.args
files by Java release version, creating separate files like javac-17.args
, javac-21.args
, etc.
- Adds support for multi-module, multi-release projects through new directory structure handling
- Implements
WorkaroundForPatchModule
class to handle compiler compatibility issues with patch module paths - Refactors debug file generation to create separate javac.args files per Java release
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
WorkaroundForPatchModule.java | New workaround class for handling unsupported patch module operations in some compilers |
ToolExecutor.java | Major refactoring to support multi-module multi-release compilation with new dependency management |
AbstractCompilerMojo.java | Updates debug file writing to generate separate files per Java release |
SourcesForRelease.java | Adds dependency snapshot tracking and output directory path for debug file generation |
Options.java | Fixes command line formatting to handle -J options properly |
SourcePathType.java | Adds equals/hashCode implementation for proper map usage |
Integration test files | New test case demonstrating multi-module multi-release functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/main/java/org/apache/maven/plugin/compiler/WorkaroundForPatchModule.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugin/compiler/SourcesForRelease.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java
Outdated
Show resolved
Hide resolved
a5ab42a
to
f462016
Compare
Before this commit, a project could be either multi-module or multi-release, but not both in same time. As a side effect of the debugging work, this commit also fixes the content of `target/javac.args` file (before this commit, the source files for all versions were mixed in the same `target/javac.args` file).
Co-authored-by: Copilot <[email protected]>
f462016
to
9a04930
Compare
Are we switching to a mode where we'd have a single project, but it would create multiple jars in one run ? Afaik, most plugins expects a single main artefact as the main output, while others side artifacts can be attached to the project, but on the same groupId/artifactId. So generating multiple main artifacts goes really against the way of doing things in maven. I'm not opposed to a change, but this would require a larger consensus imho. |
Yes, compiling a project which uses the module source hierarchy would result in many JAR files, one per module. For each JAR, the dependencies in the Note 1: this is already the case in Maven 3: any dependency declared in Maven Note 2: this idea is not only mine. I saw it independently expressed somewhere on GitHub, but couldn't find it back. For information, some of the ideas related to module-info support are also found in slightly different forms in the Christian Stein's blog, themselves based on Robert Scholte's emails on OpenJDK mailing list (references in the blog). I think that the same idea appears independently because in a modular world, the fact that Note 3: about 10 years ago, the Note 4: while Maven is still quite JAR-oriented, JAR files are not necessarily the main artifacts anymore. The main artifact could be the |
Before this commit, a project could be either multi-module or multi-release, but not both in same time. As a side effect of the debugging work, this commit also fixes the content of the
target/javac.args
file: before this commit, the source files for all versions were mixed in the sametarget/javac.args
file. After this commit, separatedjavac.args
,javac-17.args
,javac-21.args
, etc. files are produced.Directory layout choice
The directory structure produced in the
target
directory is like below:This directory structure will not be immediately usable by the Maven JAR plugin, because that plugin would rather expect the
META-INF/versions/17
path to be repeated inside each module. But we cannot easily comply with this expectation, because the Java compiler accepts only one-d
argument for all modules. We could move the directories after compilation, but incremental compilation of only a few files would require that we move the directories back to the location shown above before compilation, then move these directories again after the compilation. Furthermore, the users would not be able to compile themeselves on the command-line, unless they perform those moves manually (that would be tedious).I believe that it is easier, more convenient and less risky to leave the directory structure as produced by
javac
, and instead modify the Maven JAR plugin for reading the files at the locations shown above. An evolution of the Maven JAR plugin will be needed anyway, as the current version will not understand thoseorg.bar.module1
andorg.bar.module2
directories anyway, no matter if multi-release or not.