Skip to content

Instantly share code, notes, and snippets.

@darylteo
Created January 4, 2014 12:41
Show Gist options
  • Select an option

  • Save darylteo/8255043 to your computer and use it in GitHub Desktop.

Select an option

Save darylteo/8255043 to your computer and use it in GitHub Desktop.
Getting an Antlr task going in gradle.
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply from: 'gradle/sonatype.gradle'
group = 'com.darylteo'
version = '0.1.0-SNAPSHOT'
sourceCompatibility = 1.7
targetCompatibility = 1.7
configurations {
antlr
compile.extendsFrom antlr
}
dependencies {
antlr 'org.antlr:antlr4:4.1'
testCompile 'junit:junit:4.11'
}
def destDir = 'src/parser/java/'
def resourcesDir = 'src/parser/resources/'
sourceSets {
parser {
java { srcDir destDir }
output.dir(resourcesDir, builtBy: 'copyGeneratedTokens')
}
}
task generateParser(type: JavaExec) {
def outputDir = "$buildDir/antlr"
def target = "com/darylteo/sharpen/parser/Template.g4"
inputs.file target
outputs.dir outputDir
workingDir = 'grammars'
classpath = configurations.antlr
args += [
'-o',
outputDir,
'-package',
'com.darylteo.sharpen.parser',
target
]
main = 'org.antlr.v4.Tool'
}
task copyGeneratedParser(type: Sync, dependsOn: generateParser) {
from generateParser
into destDir
include '**/*.java'
}
task copyGeneratedTokens(type: Sync, dependsOn: generateParser) {
from generateParser
into resourcesDir
include '**/*.tokens'
}
compileJava.dependsOn copyGeneratedParser, copyGeneratedTokens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment