Skip to content

ANTLR as a named Java module #2946

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

Open
future2r opened this issue Oct 27, 2020 · 10 comments · May be fixed by #4137
Open

ANTLR as a named Java module #2946

future2r opened this issue Oct 27, 2020 · 10 comments · May be fixed by #4137

Comments

@future2r
Copy link

Hi there,
it is planned to release ANTLR4 as a named module for Java? Currently the ANTLR runtime does not have a "module-info.class". This causes problems when using it with "jlink". As we have Java 15 now and modules can/should be used since Java 9 it would be great to convert ANTLR into a named module too.

Sure, I could inject a "module-info.java" myself with "jdeps --generate-module-info" and "javac --patch-module", but this does not feel right. And it creates new problems if the jar is provided by Maven...

@Thihup
Copy link

Thihup commented Feb 15, 2022

Are there any updates on this issue?

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Feb 15, 2022 via email

@Thihup
Copy link

Thihup commented Feb 15, 2022

Hi @ericvergnaud! Thanks for the update :)

There are a couple of ways to add the module-info to the project without breaking changes. However, the build itself will require at least Java 11.

With that said,

This way, the module-info will be at the root of the Jar file. While most of the time it is just fine, some old build tools that don't recognize it yet may break. So maybe you would check the Multi-release Jar (https://openjdk.java.net/jeps/238), and put it in the META-INF/versions/11/module-info.class.

@ericvergnaud
Copy link
Contributor

Hi,

please submit a PR, that's the way we operate :-)

@alexberdnik
Copy link

PR submitted, the approach is similar to slf4j's https://github.com/qos-ch/slf4j/blob/master/pom.xml.
Decided not to touch the runtime-testsuite module as I'm not sure if it should continue to use java 8. runtime-testsuite also has a bad maven-compiler-plugin configuration - it is not clear which target is in use:

<!-- runtime-testsuite's pom.xml-->
                <configuration>
                    <release>8</release>
                    <source>9</source>
                    <target>9</target>
                </configuration>

@parrt
Copy link
Member

parrt commented Mar 6, 2023

I'm not familiar with the module stuff I'm afraid. can we be sure this won't break my simple java 8 world?

@mkoncek
Copy link

mkoncek commented Mar 30, 2023

Hi, I am a Java package maintainer, I have seen a few approaches:

  1. Add module-info.java and add a second run of maven-compiler-plugin to compile your module-info.java:
    https://src.fedoraproject.org/rpms/apiguardian/blob/30ded5f8b6808f385a3f9a5aee471649a49fd7f2/f/apiguardian.spec#_67

  2. A simpler approach is to add Atomatic-Module-Name manifest entry, this exports the contents of the whole .jar and does not require you to write your own module-info.java:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifestEntries>
            <Automatic-Module-Name>antlr4.runtime</Automatic-Module-Name>
          </manifestEntries>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>

@alexberdnik
Copy link

Hi, unfortunately the latter approach is not fully compatible with java module system, e.g. jlink tool would not work.

@mkoncek
Copy link

mkoncek commented Mar 30, 2023

I noticed the linked PR after submitting the comment, that is definitely a way to go.

@kb-1000
Copy link

kb-1000 commented Feb 4, 2024

Since bnd is already in use, would it make sense to use it to generate the module-info?
https://bnd.bndtools.org/chapters/330-jpms.html
This would work if you have to keep compatibility with building ANTLR itself on Java 8 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants