-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Accept Java module names as attached artifactId even if they differ from the project's artifactId #11549
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
Accept Java module names as attached artifactId even if they differ from the project's artifactId #11549
Conversation
…that can be attached. Still require the group and version to be the same, but allow the artifact to differ. The intend is to support multi-module project where more than one artifact may be produced.
|
Hello @gnodet. I have a question related to this pull request. Is it possible to edit the consumer POM of the attached artifacts for:
Any tip would be greatly appreciated. |
impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultProjectManagerTest.java
Show resolved
Hide resolved
kwin
left a comment
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.
If the GAV is no longer the same how can the attached artifact share the same POM (with a different artifactId)?
A consumer POM needs to be generated for each attached artifact. This is needed anyway, because the dependencies are no longer the dependencies declared in the POM. They are the intersection of the dependencies in the POM and the |
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java
Outdated
Show resolved
Hide resolved
I have the same concern, what is the pom of "automatic sub-artifactId Java Module" vs the base artifactId? this is really key, ad requires a clear design before trying to implement |
|
small note on label: "backport-4.0.x" is for backport from master branch (currently 4.1.x) to 4.0.x branch: this PR is not a backport; AFAIK |
The consumer POM for a Java module JAR would have a different artifactId (derived from the module name). |
|
IIUC, you expect to use the same consumer pom for automatic artifactIds of Java module JAR, just update the artifactId? for better understanding of this plan (that would deserve more than a small discussion in an issue in Maven core: is there a doc somewhere?), is there a convention between original artifactId and automatic artifactIds? and is there a jar associated to the original artifactId? first thought: instead of dropping the check, I'd clarify the creation an auto-artifactId from a base artifactId, as I think it is more a new pattern to enable, instead of a control to disable |
Well, the overall context is a project where you have multiple Java modules. I have provided some examples here. If I pick one (cf. an arbitrary For each such module JAR there must be a separate consumer POM as they can be used independently. These can be derived from the build POM. AFAIK there is no concept to explicitly provide a consumer POM for a module (and in most cases this should not be necessary as they can be derived from the build POM).
There seems not to be much documentation about M4 consumer POM concepts or a specification how to work with Java modules (I'd be happy to find more about it). That said, I'd be volunteering to create such concept documentation.
For a multi-module project there is not much need to create a binary (classes) JAR for the project itself, as each module should result in its own jar. Perhaps the sources or javadocs etc. could be created from the original project. This might be subject to discussion. |
The consumer POM is only generated from the main build POM for project being compiled. If we generate new artifacts dynamically, we'll have to generate the POM and attach it AFAIK. The |
|
Hello @hboutemy and all. First, there are a few Java 9 concepts that I would like to ensure that they are well known:
They are been attempts to explain these aspects on the Maven mailing list, on a wiki with proof of concept and with a real project experiment using Gradle. However, I got the feeling that the above is still nebulous to most peoples, and that the best way to advance would be to give to developers a possibility to try easily by themselves. The Maven Compiler Plugin 4.0.0-beta-3 is already capable to compile a project organized with module source hierarchy. Consequently, the output in Now about the questions:
Note that when building a project with Maven 4, we already have a
Therefore, the base
No when using the module source hierarchy. Reminder: nothing change when using the traditional package hierarchy.
The new proposed JAR plugin automatically detects when module hierarchy is used, and produces one JAR per module in that case. However, it results in an exception thrown by Maven core if the relaxation proposed in this pull request is not applied. Reminder: again, nothing change when the JAR plugin detects that the traditional package hierarchy was used. The reason why the JAR pull request mixes two tasks in the same pull request is because one of the reasons to migrate to the |
Would you mind if we add a respective (sub-) page to the Confluence as documentation of this background to Java modules? |
That would be welcome. One of the biggest difficulty we are facing with Java modules is explaining them. More documentation attempts may help. |
To make clear that the relaxation is only necessary and used in the case of multi-module JARs, the proposed change could be adapted to check whether the ...
String a1 = project.getArtifactId();
String a2 = artifact.getArtifactId();
...
// ArtifactId may differ only for multi-module projects (source roots with module name)
boolean isMultiModule = getSourceRoots(project).stream().anyMatch(sr -> sr.module().isPresent());
if (!Objects.equals(a1, a2) && !isMultiModule) {
throw new IllegalArgumentException(...);
}
... |
…e of a Java module.
|
I pushed a variation of @ascheman proposal: in addition of allowing the |
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java
Outdated
Show resolved
Hide resolved
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java
Outdated
Show resolved
Hide resolved
I'm starting to understand that one single multi-java module build gives many "what used to be classical jars, with one build (= 1 pom) per jar" then this is not about relaxing attach strategy now I get that we have one build pom, that generates many consumer poms with their own output modular jar. |
|
one question: one reason for having one build pom per sub-project is that there are resources, assemblies, and everything that goes beyond just the compiler step, and also there are unit tests, and ITs, and everything else in this "one single pom for one single compiler run that build many independent Java modular jars", how do you handle the flexibility about everything that is not .class in the modular jars, and their tests, etc? |
|
@gnodet I don't get how v4 API permits to attach something to a pom (in v3 a MavenProject) that does not exist |
This is not limited to the v4 API. The jar plugin will attach the artifacts and the poms when building a modular project. AFAIK central will reject any upload for an artifact without any matching pom. We could enforce that at install/deploy time in resolver if we want. |
The |
I don't understand. You can attach any kind of artifact to a project, it can be a jar, a pom, or whatever. From the install/deployment POV, there's no difference between a main pom, a consumer pom, or the jar produced. Those are all artifacts (groupId, artifactId, version, extension, classifier) that point to file on the filesystem. Then, if we talk about semantics, I'm not sure yet how to produce those poms, but I think the overall idea is to create something similar to the consumer POM for the project, with small modifications to follow the rules of a specific JPMS module (not a maven module).
I don't think that's a goal. We're not talking about subprojects here, just JPMS modules that are created from a single POM file. Maybe you're thinking about plugins that would generate other kind of resources ? For example a plugin that would read the class files and generate something to be included in the jar ? That would definitely not work without adapting the plugin to support this JPMS module layout. Or you could configure multiple executions, each one pointing to the specific output directory of the module. For example with the modular project IT, we'll have |
Correct, each JAR is a single module, and the multi-module build is produced by one single invocation of the compiler. I agree that "multi-module JARs" may be confusing. "Module hierarchy" when talking about the directory layout, or just "multi-module" otherwise, would probably be safer.
Resources are supported by the new
Indeed, |
|
Correction to the above: |
|
thank you @gnodet and @desruisseaux for your explanations:
I now see the wider picture: at compile, test and jar level, I see that this modular-sources approach improvements have been done or are planned (I suppose there is an equivalent IT in Surefire and in Maven Jar Plugin? I don't see in https://github.com/apache/maven-jar-plugin/tree/master/src/it , I ignore fore now Surefire as its code is too complex for me :) ) I'm still not yet completely convinced at install/deploy level: I'll try to dig into my feeling to be more actionable whatever I discover when going more in-depth no modular sources IT in https://github.com/apache/maven-install-plugin/tree/master/src/it nor https://github.com/apache/maven-deploy-plugin/tree/master/src/it : this is one of my biggest concerns for now I'm working on many plugins that iterate over everything that will be installed/deployed: Maven Artifact Plugin, CycloneDX and SPDX Maven Plugins
Currently, GAV coordinates from Artifacts are the same as MavenProject from where they come With one Maven project producing many modular jars based on their modular source structure, now I get that there will be artifactIds deducted from module name in modular sources I won't stay more theoretical, it become too long; Is there a common sample modular sources project that is used to test all these changes in a common team approach? And last question: from Maven core perspective, does it target Maven 4.1 only, or is it expected to be backported to some previous branches? one partial conclusion in addition is that we'll need to keep https://github.com/Geomatys/maven/wiki at Maven level, at least partially, because this is really the best design doc I now see |
hboutemy
left a comment
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.
issue title should be more restrictive than just "relax" but at least something talking about modular sources (good news for me: we don't relax and let anything happen, but replace with another well defined constraint)
"support modular sources: " prefix?
"accept attached artifactId from module different from project's one"
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java
Outdated
Show resolved
Hide resolved
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java
Outdated
Show resolved
Hide resolved
I'm not sure about which changes will be required in surefire yet. I don't know that code base well either.
This should not require any change at all. Install / deploy just take attached artifacts and delegate to the resolver for installing / deploying. This very PR is exactly about being able to attach those generated artifacts to the project, without being limited to the same artifactId. This is the only required change AFAIK.
Yes, and all the JAR/POMs for the modules will be available from
Good point. This has to be checked. This would mean we have conflicting module names somehow I suppose. @desruisseaux ?
I really don't expect any change for installation/deployment. The only changes is for plugins that would need to adapt to the JPMS layout.
Maven-core has provided the needed infrastructure with the v4 API in 4.0.x, but most of the work is in the v4 core plugins (resources, compiler, jar...). A project migrated from Maven 3 won't see any change.
|
Well, we have a collection of about 40 samples of Java Modules use cases. 35 of them (all applicable ones) have been migrated to Maven 4 (or its current state of support for Java Modules). And we already found out some (new) challenges and verified what works by now, e.g.., compiler support is very good by now. One of the open challenges is the incomplete support of |
|
In general, let me remind you of some ongoing documentation of Java Modules support in Confluence. |
An integration test is provided with the apache/maven-jar-plugin#508 pull request, but it depends on this PR. For other plugins, the current state is in the link provided by Gerd in above comment.
In addition to the samples given by Gerd in above comment, I use a clone of the Apache SIS project where the Gradle build has been replaced by Maven 4. The features tested are:
The result is much better than what we could achieve by hacking the Gradle build. In particular, we had to create some
The work is backported to 4.0.x, but as Guillaume said, the changes that are done in Maven core are small adjustments. The biggest changes where done about one year ago, with the introduction of
Yes, this is also planed. I already started an updated version of the user guide, but I'm not sure where to put it as it is of wider scope than only the compiler plugin.
Indeed, a check would be desirable, maybe in a separated pull request. For now, the risk is slightly reduced by naming tradition (not a formal convention), as Maven artifacts often have a |
…rom the project's artifactId (apache#11549) The intend is to support multi-module project where more than one artifact may be produced.
Pull request #1838 added a verification in
DefaultProjectManagermaking sure that an artifact attached to a project has the samegroupId,artifactIdandversionas the project. This pull request relaxes that restriction by allowing theartifactIdto be different, but still requires thegroupIdandversionto be the same.The intend is to support multi-module projects where more than one artifact may be produced. It was briefly discussed in apache/maven-compiler-plugin#959 (comment). This is needed by the new Maven JAR Plugin proposal. Note that classical projects (package hierarchy) are expected to continue to use the same
artifactIdas before.