Skip to content

Add easy support for automatic module name #520

Closed

Description

@dmlloyd

New feature, improvement proposal

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.

Thanks!

Activity

  1. added
    enhancement
    on Jan 14, 2026
  2. added 2 commits that reference this issue on Jan 14, 2026
    0231ebd
    992e5a9
  3. desruisseaux commented on Jan 15, 2026

    @desruisseaux

    The current plugin allows the following:

    <configuration>
      <archive>
        <manifestEntries>
          <Automatic-Module-Name>org.foo.bar</Automatic-Module-Name>
        </manifestEntries>
      </archive>
    </configuration>

    The pull requests #521 and #522 would allow to get the same result with the following, except for the warning when a module-info.class is present:

    <configuration>
      <automaticModuleName>org.foo.bar</automaticModuleName>
    </configuration>

    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:

    <configuration>
      <archive>
        <manifest>
          <automaticModuleName>org.foo.bar</automaticModuleName>
        </manifest>
      </archive>
    </configuration>

    Note that this is not really shorter than the existing.

  4. dmlloyd commented on Jan 16, 2026

    @dmlloyd
    Author

    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.)

  5. added 2 commits that reference this issue on Jan 16, 2026
    6cddbbb
    cc10a7e
  6. elharo commented on Jun 14, 2026

    @elharo
    Contributor

    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.

  7. desruisseaux commented on Jun 14, 2026

    @desruisseaux

    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.

  8. dmlloyd commented on Jun 15, 2026

    @dmlloyd
    Author

    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.

  9. elharo commented on Jun 15, 2026

    @elharo
    Contributor

    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.

  10. dmlloyd commented on Jun 15, 2026

    @dmlloyd
    Author

    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.

    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.

  11. desruisseaux commented on Jun 15, 2026

    @desruisseaux

    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.

  12. dmlloyd commented on Jun 15, 2026

    @dmlloyd
    Author

    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.

  13. desruisseaux commented on Jun 15, 2026

    @desruisseaux

    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.

  14. desruisseaux commented on Jun 16, 2026

    @desruisseaux

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions