After further research and testing I discovered that the antlr-ant task
referenced by my build configuration only supported antlr version 2. It
seems that the antlr3-ant task is not on any repository that I can find, to
solve this problem I have created a 'build-deps' folder in my project and am
loading the local task jar to process the grammar files. My build script
looks like the following (note: I am using the latest version of gradle from
trunk, version 0.9+):
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.antlr', name: 'antlr-runtime', version: '3.+'
compile group: 'commons-cli', name: 'commons-cli', version: '1.+'
testCompile group: 'org.antlr', name: 'gunit', version: '3.+'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
task generateGrammarSources (description: 'Invokes the antlr3-task from ant
to generate grammar sources') << {
generatedDir = new File(project.buildDir.toString() + '/generated-src/')
generatedDir.mkdirs()
ant {
taskdef(name: 'antlr3', classname:
'org.apache.tools.ant.antlr.ANTLR3'){
classpath {
fileset(dir: 'build-deps', includes: 'antlr3-ant.jar')
}
}
antlr3(target: 'src/main/antlr3/Calculator.g',
outputdirectory: 'build/generated-src/')
}
}
compileJava.dependsOn generateGrammarSources
This still does not work. I need to add the ANTLR tool to the classpath of
Ant so that it can compile the grammar files. The build error output is
here:
[ant:antlr3] Exception in thread "main" java.lang.NoClassDefFoundError:
org/antlr/Tool
I'm sure that adding the ANTLR tool dependency to the Ant classpath is a
simple addition to the build script, I haven't found the solution yet. Any
advice is appreciated.
Kind Regards,
Chris
chrismolozian wrote:
>
> Thanks for the links to the documentation, I have been trying to get the
> antlr-ant task to execute through gradle. I have the following build
> configuration script so far:
>
> apply plugin: 'java'
>
> repositories {
> mavenCentral()
> }
>
> configurations {
> antAntlrConf
> }
>
> dependencies {
> antAntlrConf 'ant:ant-antlr:1.6.+'
> compile group: 'org.antlr', name: 'antlr-runtime', version: '3.+'
> testCompile group: 'junit', name: 'junit', version: '4.+'
> }
>
> task generateGrammarSources (description: 'Invokes the antlr3-task from
> ant to generate grammar sources') << {
> generatedDir = new File(project.buildDir.toString() +
> '/generated-src/')
> generatedDir.mkdirs()
>
> ant {
> taskdef(name: 'antlr',
> classname: 'org.apache.tools.ant.taskdefs.optional.ANTLR',
> classpath: configurations.antAntlrConf.asPath)
>
> antlr(target: 'src/main/antlr3/Calculator.g', outputdirectory:
> 'build/generated-src/')
> }
> }
>
> compileJava.dependsOn generateGrammarSources
>
> This does not work yet, the build fails with the following error:
>
> gradle clean generateGrammarSources
> :clean
> :generateGrammarSources
> Trying to override old definition of datatype antlr
>
> FAILURE: Build failed with an exception.
>
> I don't understand what it means by "Trying to override old definition of
> datatype antlr" I have been working on it for a while and was hoping I
> could get a few points in the right direction.
>
>
> Adam Murdoch-2 wrote:
>>
>>
>>
>> On 8/04/10 11:30 AM, chrismolozian wrote:
>>> Thanks very much for the fast response. I'm not well versed in either
>>> Ant or
>>> Gradle yet to begin connecting the two together, is there some
>>> documentation
>>> you could point me to that might help.
>>>
>>
>> Here's the chapter about using Ant with Gradle:
>> http://gradle.org/0.9-preview-1/docs/userguide/ant.html
>>
>> Section 17.1.1 has some information about using external tasks in
>> Gradle. There's also some more examples in the Cookbook at:
>> http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-3rdpartytools
>>
>>
>> --
>> Adam Murdoch
>> Gradle Developer
>> http://www.gradle.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
>
--
View this message in context:
http://old.nabble.com/using-antlr-in-gradle-tp28171481p28201575.html
Sent from the gradle-user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email