Skip to content

Instantly share code, notes, and snippets.

@rgoulter
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgoulter/b04abfeb8c52b9e31377 to your computer and use it in GitHub Desktop.
Save rgoulter/b04abfeb8c52b9e31377 to your computer and use it in GitHub Desktop.
Gradle for an Antlr4, Scala project. Can generate Eclipse files, too.
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'me.champeau.gradle.antlr4'
buildscript {
repositories {
maven {
name 'JFrog OSS snapshot repo'
url 'https://oss.jfrog.org/oss-snapshot-local/'
}
jcenter()
}
dependencies {
classpath 'me.champeau.gradle:antlr4-gradle-plugin:0.1'
}
}
repositories {
jcenter()
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.1'
// Runtime only needs antlr4-runtime, not the whole antlr4.
compile 'org.antlr:antlr4-runtime:4.5'
// Customise antlr4 version, for buildscript
antlr4 'org.antlr:antlr4:4.5'
}
// Have Gradle/Antlr4 use the same output folder as Maven
// so that it plays nicely with Eclipse.
antlr4.output = new File("target/generated-sources/antlr4")
// make the Java compile task depend on the antlr4 task
compileJava.dependsOn antlr4
// add the generated source files to the list of java sources
sourceSets.main.java.srcDirs += antlr4.output
@rgoulter
Copy link
Author

While I'm sure this isn't idiomatic Gradle, I don't know what would be. I know that this works well enough for my purposes.

It can generate Eclipse project files. A gradle antlr4 is needed, though, after a gradle clean.

@rgoulter
Copy link
Author

Antlr4 generated src went to build/generated-src.
Generated classes to bin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment