antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.22k stars 3.29k forks source link

Errors trying to build, run Java runtime tests on fresh M1 mac with java 16 #3390

Open parrt opened 2 years ago

parrt commented 2 years ago

I get with this error via command line:

$ mvn -DskipTests clean install
...
Java version: 16.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home
...
[INFO] ANTLR 4 Runtime Tests (2nd generation) ............. FAILURE [ 12.637 s]
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project antlr4-runtime-testsuite: Fatal error compiling: java.lang.IllegalAccessError: class org.antlr.v4.test.runtime.CommentHasStringValueProcessor (in unnamed module @0x2c7df4fa) cannot access class com.sun.tools.javac.model.JavacElements (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.model to unnamed module @0x2c7df4fa -> [Help 1]

Adding a series of these to maven-compiler-plugin from this doc doesn't help:

<configuration>
      ...
      <fork>true</fork>
      <compilerArgs>
                            <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
KvanTTT commented 2 years ago

I've encountered the same problem recently: https://stackoverflow.com/questions/70203702/unable-to-build-antlr4-on-ubuntu-due-to-package-is-not-visible-errors (Forgot to add my answer to StackOverflow). But maybe you add not all required arguments. Try adding the following arguments to maven-compiler-plugin section in the root pom.xml:

...
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
    <source>${maven.compiler.source}</source>
    <target>${maven.compiler.target}</target>
    <compilerArgs>
        <arg>--add-exports</arg><arg>jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
        <arg>--add-exports</arg><arg>jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
        <arg>--add-exports</arg><arg>jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
        <arg>--add-exports</arg><arg>jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
    </compilerArgs>
</configuration>
...
parrt commented 2 years ago

I just created a branch for that but I am trying to figure out why it won't build from a clean. It always fails on the run time tests because that requires the installation of the software, which is Circular dependency... Not sure why they built a tool doesn't figure this out. Let me create the PR and you can take a look.

I'm trying to catch up with antlr now, but I can't get it to build reliably haha.

KvanTTT commented 2 years ago

Also, it seems like Java 7 does not support compilerArgs in pom. I think it's the right time to update it, see https://github.com/antlr/antlr4/discussions/3369

parrt commented 2 years ago

Can you give me the sequence you used to compile from a fresh clone? I first do this to make sure everything is fresh:

$ rm -rf ~/.m2/repository/org/antlr/antlr4*
$ mvn clean
$ mvn -DskipTests install 

The last command there fails trying to build the runtime tests because it's looking for the plug-in or something. The only error I get even with -X is to say compile error. Even this doesn't work when I try to build the individual things:

mvn -X -pl .,antlr4-runtime install

For some reason I can't find the runtime module no matter what I name it. Making other modules like this works.

KvanTTT commented 2 years ago

I remember that I've also failed on mac (not M1) when I've tried it recently. I've ended up with working tool tests but with not working runtime tests. Are tool tests working on your mac? I should get another try but later. Also, you can try to use another version of Java.

But it eventually works fine on my Ubuntu.

parrt commented 2 years ago

Everything works if I use intellij (all hail jetbrains!) but that is using open jdk 1.8 not 16. Meaning that I can compile and run tool and run time tests

parrt commented 2 years ago

See the problem is I have over here https://github.com/antlr/antlr4/pull/3391 when trying to install mvn jar from the command line

parrt commented 2 years ago

Maven is literally beyond my ability to understand. I've wasted three hours so far today and I've made zero progress getting this to compile. On the run time tests I can clean validate and compile but not test or install. It indicates that it gets a compile error despite clearly compiling.

parrt commented 2 years ago

I would love to just leave Java behind at this point because of the build tools

KvanTTT commented 2 years ago

Don't worry, eventually, we'll handle it. But unfortunately, I'm not able to help you now because it's too late for me (after midnight).

parrt commented 2 years ago

Ok, I will try to just build within intellij for now. It looks like it might be a problem to merge the PR because java 8 does not like those parameters or something as it's not compiling.

parrt commented 2 years ago

Ah. it's java 16 trying to process the annotations during compile phase for testing that fails.

Open jdk 1.8 (/Users/parrt/Library/Java/JavaVirtualMachines/liberica-1.8.0_302/bin/java) in intellij builds no problem (after mvn generates source files from grammars etc...) but jdk 1.8.0 from oracle does not.

I take that back. it's mvn just failing:

[INFO] Reactor Summary for ANTLR 4 4.9.4-SNAPSHOT:
[INFO] 
[INFO] ANTLR 4 ............................................ SUCCESS [  0.820 s]
[INFO] ANTLR 4 Runtime .................................... FAILURE [  1.293 s]
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project antlr4-runtime: Compilation failure -> [Help 1]
...

Same error from runtime/Java dir.

This works with oracle jdk manually compiling:

~/antlr/code/antlr4/runtime/Java/src $ javac -version
javac 1.8.0_311
~/antlr/code/antlr4/runtime/Java/src $ javac -d /tmp org/antlr/v4/runtime/*.java org/antlr/v4/runtime/*/*.java org/antlr/v4/runtime/*/*/*.java

Maybe mvn plugin versions aren't compatible and we need to update all those version nums in poms???

All tests pass in java runtime, python, tool from intellij so far if i just compile not mvn.