asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
625 stars 173 forks source link

Automatic-Module-Name is undefined in MANIFEST file #1239

Closed leadpony closed 10 months ago

leadpony commented 11 months ago

The artifacts in my project are JPMS (Java Platform Module System) modules and one of them depends on AsciiDoctorJ API. It works fine with both the stable 2.5.10 and the latest 3.0.0-alpha-1.

module-info.java in my module is like this.

module my.module {
    requires asciidoctorj.api;
}

Building this module using Maven emmits the following message:

[INFO] Required filename-based automodules detected: [asciidoctorj-api-3.0.0-alpha.1.jar]. Please don't publish this project to a public artifact repository!

This message prevents me from publishing my module to the Maven Central.

Fixing this problem is very easy. It just requires to add Automatic-Module-Name attribute in the build.gradle in asciidoctorj-api project to name the automatic module explicitly:

jar {
  bnd(
    'Bundle-Name': 'asciidoctorj-api',
    'Bundle-SymbolicName': 'org.asciidoctor.asciidoctorj-api',
    'Automatic-Module-Name': 'org.asciidoctor.asciidoctorj.api'
  )
}

This does harm nothing when JVM is running without module path.

Please note that the name given for the automatic module illustrated above is simply constructed with the group ID and the artifact ID replacing - with .. You can change it if there is more appropriate name for this project.

Please also see this excellent article: Automatic-Module-Name: Calling all Java Library Maintainers

robertpanzer commented 11 months ago

Thanks for the issue! I am fine with the names asciidoctorj.api, asciidoctorj.core etc. About your example I'd prefer to not put it into the configuration of the bnd plugin. Its purpose is for building OSGi modules, and I think it might be confusing to find that property there.

For 3.0 I'd prefer to also add proper module-info files that also declare the dependencies.

leadpony commented 11 months ago

@robertpanzer

Thank you for your reply.

I am fine with the names asciidoctorj.api, asciidoctorj.core etc.

Which one you mean?

  1. asciidoctorj.api
  2. org.asciidoctor.asciidoctorj.api

Module names must be globally unique and traditionally the reverse DNS notation is used to secure the uniqueness.

Its purpose is for building OSGi modules, and I think it might be confusing to find that property there.

I agree.

My request is:

  1. Reserve a module name for future modularization of AsciidoctorJ.
  2. Add it to the MANIFEST.MF for library users.

The following sentense is from the book Java 9 Modularity published by O'Reilly:

Reserving a module name with Automatic-Module-Name in the manifest is something you should do as quickly as possible.

My request is not about the full modularization equipped with a module descriptor, bacause it takes long time as in the issue #1036, which seems to be posted 2 years ago.

robertpanzer commented 11 months ago

If I understand correctly the current automatic module names would be asciidoctorj.api and asciidoctorj. Changing that to org.asciidoctor.asciidoctorj.api would be a breaking change imo, since AsciidoctorJ should work with JPMS atm and users might already be relying on that.

We can consider the move to org.asciidoctor.asciidoctorj.api for AsciidoctorJ 3.0, but not for 2.5.x.

leadpony commented 11 months ago

Yes, you are right.

Currently the users of AsciidoctorJ are using filename-based, non-canonical module names because the library lacks Automatic-Module-Name entries in the manifest.

I hope that 3.0.0-alpha.2 contains the modification to the manifest files.