markjfisher / antlr4-plugin

Gradle Plugin for antlr4 development
Apache License 2.0
6 stars 2 forks source link

Setting classpath for JavaExec #4

Open darylteo opened 10 years ago

darylteo commented 10 years ago

Hi there! I have been looking into getting antlr4 running within a Gradle build and I have come up with the following code which I think you will find useful.

task generateParser(type: JavaExec) {
  def outputDir = "$buildDir/antlr"

  def deps = ['org.antlr:antlr4:4.1']
  def target = 'grammars/Template.g4'

  classpath = configurations.detachedConfiguration(*deps.collect({
    dependencies.create(it)
  }))

  args += [
    '-o', outputDir,
    target
  ]

  main = 'org.antlr.v4.Tool'
}

Some of the stuff there I got from looking at your source. However I decided I simply needed the task without meddling around with plugins. Hope you find this code useful anyway (because now you don't need to have those dependencies in your user's buildscripts). Sorry a bit lazy to submit a pull request =)

markjfisher commented 10 years ago

Many Thanks for this, I'll have a look at merging this into the main code to remove the dependencies. Anything to make using the plugin as simple as possible is very welcome.

darylteo commented 10 years ago

Look for me on the #gradle channel on irc.freenode if you want any more tips.

Also, this is working well for me thus far. Granted, I haven't really pushed it much yet (I'm still learning the ropes with Antlr) https://gist.github.com/darylteo/8255043

Daryl