Better Java Module System support for Maven 4 #11
Replies: 11 comments 37 replies
-
Questions comming into my mind
|
Beta Was this translation helpful? Give feedback.
-
As I said in out chat, for me it is hard to imagine the middle ground where the Maven build is based on the Java's From a user's perspective I would want to mainly modularize my project using Java modules and use a single maven module for adding in the other aspects about the project. Assuming that not everyone will be wanting such a model I would think that if there are multiple maven sub-modules in such a project the dependencies between the (sub)modules should not be required to be stated including the module structure as this does follow from the Java module declaration. TLDR; don't make me redefine information that is implied by the On top I would want to be able to opt-out of Maven features or maybe have a different "mode" when incorporating the Java modules so that the compilation only ever can be the expected sequence of javac and jar tool calls. Something like this might even be a precondition to be able to merge the two worlds without making it super complicated. TLDR; when merging opt for the simplest model possible even if that removes support for "advanced" Maven features. I also want to mention that doing a major change like this surely needs to touch the code in many central places. This is by nature the opposite of stability for those that just want to keep using maven "as is". So the way such a change is made must make sense with stability in mind. For example, if this is first added to a new major version the issue is little as a major version change is usually done very conscious and after looking at the pros and cons. It will be hard balancing the different users (without Java modules vs with Java modules) against each other. |
Beta Was this translation helpful? Give feedback.
-
Thinking a bit on how Maven and Java Module information can merge more smooth might be to look at a set of annotations defined by Maven to be put in the Christian and me have been looking at annotation like this in context of bach and there we came to the conclusion that just using programmatic setup is easier and more powerful at the same time so it is not worth it in the programmatic approach bach has. But for Maven with declarative basis of the |
Beta Was this translation helpful? Give feedback.
-
Regarding (build time) dependency management I wonder if it shouldn't be possible to provision ClassPaths from the If other coordinates for publication of the resulting artifact(s) like GAV, developer, licence, repository and other information could be moved to a For multi module builds I still would like to define common dependency meta data only once, like it is done in |
Beta Was this translation helpful? Give feedback.
-
Am just putting this here, the ongoing Maven4 work: https://github.com/Geomatys/maven-compiler-plugin/wiki |
Beta Was this translation helpful? Give feedback.
-
Thanks @cstamas for pinging me. Work for JPMS are ongoing in both Maven 4 core and in the Maven compiler plugin. The implementation of some of the proposals described below are already advanced, but it is still possible to modify the approach according feedbacks. Change already done in Maven 4 core APIProblemPlacing a JAR on the class-path or on the module-path makes a difference: services are not detected by Solution in Maven 4-alphaMaven 4 tries to resolve that problem by giving to users a way to control where to place a JAR file. It uses the <dependency>
<groupId>org.foo</groupId>
<artifactId>bar</artifactId>
<type>modular-jar</type>
</dependency> Some values for
This approach is opportunistically expanded to other kinds of paths:
Note however that while those types have already been introduced in Maven 4, no plugin take them in account yet. The first plugin to be updated is the compiler plugin (discussed below). Change for Maven 4 core not yet done or discussedThe way to specify the directory of source code in Maven 3 is too minimalist for the evolution of the Java language in the last decade: <build>
<sourceDirectory>src/main/java</sourceDirectory>
</build> If for any reason the code is spreads between two or more directories, developers have to use <sources>
<source module="org.foo.bar" release="11">src/org.foo.bar/java</source>
<source module="org.foo.biz" release="11">src/org.foo.biz/java</source>
<source module="org.foo.biz" release="17">src/org.foo.biz/java17</source>
<sources> Notes:
I have not yet done a formal proposal for this change on the Maven developer mailing list, but hope to do so after a working version of the new compiler plugin become available. Note that while the above structure does not exist yet in the Maven model, the new Maven compiler plugin is already ready for it. It already uses a (source directory, module name, Java release) structure internally. Change in Maven compiler pluginThe changes in Maven 4 core were relatively minor. But the change in Maven compiler plugin is a major rewrite. All plexus dependencies are removed. The Plexus compiler is replaced by After we get a workable compiler plugin, the next plugins to update will be javadoc, tests and JAR. But I think they will be easier to upgrade. Except Javadoc, for which I would propose to merge with the compiler plugin, but I keep this debate for another time. |
Beta Was this translation helpful? Give feedback.
-
This is a large topic. I apologise in advanced for another long comment. It may be a good idea to put these things in some kind of specification document so that different aspects can be discussed separately and do not get mixed up. My thoughts on the topic: I would consider taking the Java Module System into central consideration when thinking about the "next step" of improving Java build tools (both Maven and Gradle). It has the potential to make the tools better even for projects that do not use the Module System. In other words, when we discuss the future of the build tools, we should stop thinking about the "Projects using the Module System" being the "special case". But rather seeing "Projects using the Module System" as the default case (we want to get to). That will help to reach the goal that it actually becomes the default in the future, which will then allow the whole ecosystem to profit and use all the JDK tooling (jlink etc) seamlessly. Then, one can re-evaluate the convention-over-configuration status for "standard" Java projects. The Module System allows us to move responsibility from the build tools into Java itself. Which in turn allows for more conventions and the build tools to move into the background. Which tackles one of the major problems they have right now (IMO): There is still too much configuration needed in cases where projects are (more or less) "standard Java projects". I emphasize with what @ascheman wrote above. In my mind a perfect build system for the Module System can move into the background. Which means there are no additional files in the single projects (of a multi-project) needed as everything can be a convention or a central configuration. I did a proof-of-concept for that with Gradle: https://github.com/jjohannes/java-module-system Here is a slide from my presentation on the topic, which attempts to split up responsibilities between the Module System and the Build Tool. That is, all that can be expressed in the Module System about Modules and their relationship is done there. Everything else that is needed to retrieve third party modules and build the software is done by the build tool: These are the major functionalities we have in Gradle / Gradle plugins that would be needed in a corresponding Maven approach:
Note that the topics of defining versions and variant selection centrally and centrally patching metadata to make it "perfect for my world" are the same for non-Module (classspath) projects. But thinking about this with the Module System in mind makes it clearer why it is useful to think of these as aspects of dependency management as something that should be dealt with "somewhere central" (and not in individual project POMs). I don't feel strongly about "how" these things work or will work in Maven. I just wanted to offer these thoughts as something to create a vision for a "perfect Java Module System project setup" from – with as much "convention-over-configuration" as possible. If this sounds useful, I think an interesting experiment would be to prototype the Maven Extension sketched and check how my Gradle example could be done similarly in Maven. |
Beta Was this translation helpful? Give feedback.
-
I also wish that "Projects using the Module System" become the default case. Note: just for completeness, maybe the slide should also contain the following elements in the Java's module-info side?
I mention that for emphasis that if the overlap between |
Beta Was this translation helpful? Give feedback.
-
For the record while I can agree supporting a bit better JPMS is a nice addition i hope the default stays plain classpath (or loader depending the env you evolve in) since it is current (and future for some years) ecosystem so nothing should create/require a |
Beta Was this translation helpful? Give feedback.
-
I have a slightly more minimalistic take on this. I'm thinking we could declare all dependencies in For example, any dependency found in As others have hinted, maybe we could do away with Thoughts? |
Beta Was this translation helpful? Give feedback.
-
We splitted the discussion in 4 sub-discussions: |
Beta Was this translation helpful? Give feedback.
-
More and more projects will use the java module system in future. Maven as the most prominent build tool in the Java ecosystem should have a great support for the java module system.
Beta Was this translation helpful? Give feedback.
All reactions