I have created new Gradle project, added
apply plugin: \'antlr\'
and
dependencies {
antlr \"org.antlr:antlr4:4.5.3\"
What helped me is two things:
@header{
package com.example.something.antlrparser;
}
to the top of the grammar file.src/main/antlr/com/example/something/antlrparser/grammar.g4
Now when I run the generateGrammarSource
gradle task, .java
files are generated in /build/generated-src/antlr/main/com/example/something/antlrparser/*.java
and they are automatically picked up by IntelliJ as well as compilable by gradle.
The build.gradle
file is just:
group 'com.example.something'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'antlr'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
antlr "org.antlr:antlr4:4.5" // use ANTLR version 4
}