Skip to content
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

Java: Can't use ANTLR 4.11.1 on Java 8 #3994

Closed
raylras opened this issue Nov 30, 2022 · 2 comments
Closed

Java: Can't use ANTLR 4.11.1 on Java 8 #3994

raylras opened this issue Nov 30, 2022 · 2 comments

Comments

@raylras
Copy link

raylras commented Nov 30, 2022

I am using Java 8, Gradle 7.4.2 and ANTLR 4.11.1 to develop. When I run the gradle task generateGrammarSource I got an exception:

Execution failed for task ':generateGrammarSource'.
> org/antlr/v4/Tool has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

The build.gradle file:

plugins {
    id 'java'
    id 'antlr'
}

java {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.antlr:antlr4-runtime:4.11.1'
    antlr 'org.antlr:antlr4:4.11.1'
}

sourceSets {
    generated {
        java.srcDir 'generated-src/antlr/main'
    }
}

generateGrammarSource {
    maxHeapSize = '64m'
    arguments += ['-visitor', '-listener', '-long-messages']
    outputDirectory = new File(buildDir.toString() + '/generated-src/antlr/main')
}

That means that ANTLR 4.11.1 on maven central uses Java 11 to build and does not work with Java 8.
I noticed that the project readme is still marked Java 7+, so I guess this might be a build error.
I tried downgrading ANTLR to 4.9.3 and it worked fine with Java 8.

@Commodore68
Copy link

See the release notes for antlr 4.10 https://github.com/antlr/antlr4/releases/tag/4.10 starting in 4.10 antlr must be built with java 11 but can still be run on Java 8.

@raylras
Copy link
Author

raylras commented Dec 1, 2022

See the release notes for antlr 4.10 https://github.com/antlr/antlr4/releases/tag/4.10 starting in 4.10 antlr must be built with java 11 but can still be run on Java 8.

Everything works fine after using Java 11 SDK and setting the language level to Java 8. Problem solved, thank you.

@raylras raylras closed this as completed Dec 1, 2022
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

No branches or pull requests

2 participants