You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if there was a configuration property to easily set the automatic module name of a JAR, since this is a very frequent activity when migrating projects to use modules. It should print a warning (and do nothing) if a module descriptor is found in the project.
I have a patch to do this, which I will propose in a PR forthwith.
This is admittedly shorter, but is it worth to have two places for configuring the same attribute in the plugin configuration?
If, nevertheless, there is a desire to handle the Automatic-Module-Name attribute in a special way, if we want to be consistent with other attributes that are handled in a special way such as Main-Class, then the attribute would need to be added in org.apache.maven.shared.archiver.ManifestConfiguration. The XML fragment would become like below:
All your points are valid; my goal however isn't (only) less typing. I want to be able to supply an automatic module name using just a build property, e.g. -Dmaven.jar.automaticModuleName=org.foo.myproject (or more likely, a value at the top of my POM).
This cannot really be done in the obvious way with the archiver configuration because IIUC if a property expression has an empty value, then the value will be an empty string, causing an empty Automatic-Module-Name property to be added to the manifest.
The convenience is, I'd say, about equivalent to that of detectMultiReleaseJar which is also defined at this level rather than the archiver level.
(That said, I see I ironically forgot to account for the empty string in my PRs, so I'll fix that now.)
I don't think the automaticModuleName should be set from the command line. Setting it from the pom is more reliable and reproducible. I'm very tempted to close this one as won't do.
I also believe that the module name needs to be stable and predictable for the users of the JAR, and therefore that we should encourage the declaration of module name in a versioned file. If not in module-info.java, then at least in the pom.xml file.
There are many things that should not, as a matter of principle, be set from the command line. However, the ability to do so in this case is a merely side-effect of allowing the use of a property to configure the name. Every POM (that I work with at least) declares properties. I should be able to declare my automatic module name among them, for maximum simplicity and clarity (the user should not have to dig down into build config to know what the automatic module name is). This only takes one additional line for the user, and doesn't interfere with the configuration of other unrelated manifest properties.
I think this one is a no-go for now. It doesn't feel right to allow this to be set from the command line. In this case that means this should not be a property. I'm not convinced this should ever be set by anything other than module-info.java but even if it should there would have to be another other way to do this. This approach has too strong a downside.
I'm not convinced this should ever be set by anything other than module-info.java but even if it should there would have to be another other way to do this.
They're a critical migration step and Maven should have a way to easily define them. I think your given standard - that things should be forbidden from being properties on the basis of not wanting users to set them from the command line - is unreasonable, and is also violated many many times over by nearly every parameter in nearly every standard Maven plugin, most of which should definitely not normally be command-line settable. I don't think it makes sense to have my change, small as it is, be ground zero for introducing some new policy though.
But even if your standard were somehow arguably reasonable, it would be far more appropriate to suggest another mechanism for it (assuming you have a better idea), than to unilaterally close the issue and PR with just a few vague bits of opinionated feedback. Surely you understand the importance of improving modularity support in Maven. This is poor maintainer behavior no matter how you slice it, and I hope you reflect on that and reconsider.
Module name in MANIFEST.MF file is indeed a different thing that module name on module-info.java. As @dmlloyd said, it is a compromise created by Oracle for allowing a gradual transition for projects that are not yet able to provide a real module-info.java.
In my understanding, the root of the problem is that a mechanism already exists in Maven 3, but it does not work well with properties. While setting module name on the command line is not something that I would like to encourage, using properties is nevertheless possible in Maven for all sort of configuration, and we could expect MANIFEST.MF configuration in general (including automatic module name) to work with properties too. I would like to clarify what are the impediment in using properties for configuring tħe MANIFEST.MF file.
As said in my previous comment, I would prefer to either fix the current <manifestEntries> way rather than introducing a new way, or if a new way is necessary, to put it into the existing <manifest> element rather than creating a new element having its own independent existence.
As said in my previous comment, I would prefer to either fix the current <manifestEntries> way rather than introducing a new way, or if a new way is necessary, to put it into the existing <manifest> element rather than creating a new element having its own independent existence.
Should <detectMultiReleaseJar> also be in the same boat then and be reevaluated? I modeled this change after that one.
Should <detectMultiReleaseJar> also be in the same boat then and be reevaluated? I modeled this change after that one.
Good question. I don't know what was the rational at that time, but maybe it was because <detectMultiReleaseJar> does not control directly the Multi-Release: true attribute in META-INF.MF since Maven makes its own decision based on auto-detection. Also in principle, the effect is wider than only the MANIFEST.MF file because the JAR plugin should add the *.class files for other versions using the --release option (I'm not sure that the current plugin does that, but it should for allowing the jar tool to perform additional checks).
By contrast, the <mainClass> element inside <manifest> should have an effect strictly limited to the META-INF file. I suggest to model an <automaticModuleName> on that instead.
Note: if you decide to create a new pull request or edit the existing one, I suggest to target only the master branch instead of creating two pull requests for the two branches. It improves the chances that the discussion happens in one place, and the pull request created after the merge on master can be clearly identified as a backport.
Note: if I remember right, the class that defines the <archive> element is outside the Maven JAR Plugin. I think it is in some shared library (maybe Maven Archiver). It makes this change less easy to do. An easier approach may be to do this change after #508 is merged instead (if 508 is accepted). The latter is a rewrite of the JAR plugin but using java.util.spi.ToolProvider instead of Maven Archiver. The definition of <archive> could easily be migrated in the JAR plugin after 508, thus making easier to add elements.
508 is waiting only for Maven 4.0.0-rc6 before it can be submitted. We will need to resolve conflicts caused by commits added since the time when 508 was created, but it should be all.
Activity
Add support for automatic module name
Add support for automatic module name
desruisseaux commentedon Jan 15, 2026
The current plugin allows the following:
The pull requests #521 and #522 would allow to get the same result with the following, except for the warning when a
module-info.classis present:This is admittedly shorter, but is it worth to have two places for configuring the same attribute in the plugin configuration?
If, nevertheless, there is a desire to handle the
Automatic-Module-Nameattribute in a special way, if we want to be consistent with other attributes that are handled in a special way such asMain-Class, then the attribute would need to be added inorg.apache.maven.shared.archiver.ManifestConfiguration. The XML fragment would become like below:Note that this is not really shorter than the existing.
dmlloyd commentedon Jan 16, 2026
All your points are valid; my goal however isn't (only) less typing. I want to be able to supply an automatic module name using just a build property, e.g.
-Dmaven.jar.automaticModuleName=org.foo.myproject(or more likely, a value at the top of my POM).This cannot really be done in the obvious way with the archiver configuration because IIUC if a property expression has an empty value, then the value will be an empty string, causing an empty
Automatic-Module-Nameproperty to be added to the manifest.The convenience is, I'd say, about equivalent to that of
detectMultiReleaseJarwhich is also defined at this level rather than the archiver level.(That said, I see I ironically forgot to account for the empty string in my PRs, so I'll fix that now.)
Add support for automatic module name
Add support for automatic module name
elharo commentedon Jun 14, 2026
I don't think the automaticModuleName should be set from the command line. Setting it from the pom is more reliable and reproducible. I'm very tempted to close this one as won't do.
desruisseaux commentedon Jun 14, 2026
I also believe that the module name needs to be stable and predictable for the users of the JAR, and therefore that we should encourage the declaration of module name in a versioned file. If not in
module-info.java, then at least in thepom.xmlfile.dmlloyd commentedon Jun 15, 2026
There are many things that should not, as a matter of principle, be set from the command line. However, the ability to do so in this case is a merely side-effect of allowing the use of a property to configure the name. Every POM (that I work with at least) declares properties. I should be able to declare my automatic module name among them, for maximum simplicity and clarity (the user should not have to dig down into build config to know what the automatic module name is). This only takes one additional line for the user, and doesn't interfere with the configuration of other unrelated manifest properties.
elharo commentedon Jun 15, 2026
I think this one is a no-go for now. It doesn't feel right to allow this to be set from the command line. In this case that means this should not be a property. I'm not convinced this should ever be set by anything other than module-info.java but even if it should there would have to be another other way to do this. This approach has too strong a downside.
dmlloyd commentedon Jun 15, 2026
Are you saying that you don't understand what automatic modules are? There's some good reading about them here: https://stackoverflow.com/questions/46741907/what-is-an-automatic-module
They're a critical migration step and Maven should have a way to easily define them. I think your given standard - that things should be forbidden from being properties on the basis of not wanting users to set them from the command line - is unreasonable, and is also violated many many times over by nearly every parameter in nearly every standard Maven plugin, most of which should definitely not normally be command-line settable. I don't think it makes sense to have my change, small as it is, be ground zero for introducing some new policy though.
But even if your standard were somehow arguably reasonable, it would be far more appropriate to suggest another mechanism for it (assuming you have a better idea), than to unilaterally close the issue and PR with just a few vague bits of opinionated feedback. Surely you understand the importance of improving modularity support in Maven. This is poor maintainer behavior no matter how you slice it, and I hope you reflect on that and reconsider.
desruisseaux commentedon Jun 15, 2026
Module name in
MANIFEST.MFfile is indeed a different thing that module name onmodule-info.java. As @dmlloyd said, it is a compromise created by Oracle for allowing a gradual transition for projects that are not yet able to provide a realmodule-info.java.In my understanding, the root of the problem is that a mechanism already exists in Maven 3, but it does not work well with properties. While setting module name on the command line is not something that I would like to encourage, using properties is nevertheless possible in Maven for all sort of configuration, and we could expect
MANIFEST.MFconfiguration in general (including automatic module name) to work with properties too. I would like to clarify what are the impediment in using properties for configuring tħeMANIFEST.MFfile.As said in my previous comment, I would prefer to either fix the current
<manifestEntries>way rather than introducing a new way, or if a new way is necessary, to put it into the existing<manifest>element rather than creating a new element having its own independent existence.dmlloyd commentedon Jun 15, 2026
Should
<detectMultiReleaseJar>also be in the same boat then and be reevaluated? I modeled this change after that one.desruisseaux commentedon Jun 15, 2026
Good question. I don't know what was the rational at that time, but maybe it was because
<detectMultiReleaseJar>does not control directly theMulti-Release: trueattribute inMETA-INF.MFsince Maven makes its own decision based on auto-detection. Also in principle, the effect is wider than only theMANIFEST.MFfile because the JAR plugin should add the*.classfiles for other versions using the--releaseoption (I'm not sure that the current plugin does that, but it should for allowing thejartool to perform additional checks).By contrast, the
<mainClass>element inside<manifest>should have an effect strictly limited to theMETA-INFfile. I suggest to model an<automaticModuleName>on that instead.Note: if you decide to create a new pull request or edit the existing one, I suggest to target only the
masterbranch instead of creating two pull requests for the two branches. It improves the chances that the discussion happens in one place, and the pull request created after the merge on master can be clearly identified as a backport.desruisseaux commentedon Jun 16, 2026
Note: if I remember right, the class that defines the
<archive>element is outside the Maven JAR Plugin. I think it is in some shared library (maybe Maven Archiver). It makes this change less easy to do. An easier approach may be to do this change after #508 is merged instead (if 508 is accepted). The latter is a rewrite of the JAR plugin but usingjava.util.spi.ToolProviderinstead of Maven Archiver. The definition of<archive>could easily be migrated in the JAR plugin after 508, thus making easier to add elements.508 is waiting only for Maven 4.0.0-rc6 before it can be submitted. We will need to resolve conflicts caused by commits added since the time when 508 was created, but it should be all.