Thank you for your continued support Adam. The problem with the ANTLR tool
not being detected by the ant-antlr3 task was caused by my naive assumption
that the declared dependencies were being passed to the task's classpath. I
have adjusted my build script and all is working a treat finally. The
complete build script is attached below so that it may be of use to
gradle+antlr3 users in the future (until the gradle antlr3 plugin becomes
official).

Note that the script may not conform to the gradle style, I am still
learning the best practices...etc (I'd appreciate any suggestions you have
that would simplify and/or condense the build script further).

A few remaining tweaks that I am unsure how to make:
1. In the compileJava task I have adjusted the source directory list to
include the generated-src directory. It would be great if I could simply add
it to the list without redeclaring 'src/main/java' as a source dir.
2. In the jar task I'm adding manifest attributes, is there a property I can
use to get the version of gradle used to build with. Is there a property for
the JDK version too. (I tried using gradle -r to check all properties and
could not see one for these details).
3. Can you point me to gradle documentation about versioning practices and
how to control the major.minor.build mechanism in gradle.

Here is the build script:

apply plugin: 'java'

sourceCompatibility = 1.5
//major.version = '0'
//minor.version = '1'
//build.version = timestamp
project.version = "0.0.1"

repositories {
    mavenCentral()
}

configurations {
    grammarCompile
}

dependencies {
    grammarCompile 'org.antlr:antlr:3.+'
    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: '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/'){
            classpath {
                pathelement(path: configurations.grammarCompile.asPath)
            }
        }
    }
}

compileJava.dependsOn generateGrammarSources 

compileJava.doFirst {
    source = ['src/main/java', 'build/generated-src']
}

jar {
    manifest {
        attributes  "Implementation-Title": project.name, 
                    "Implementation-Version": project.version,
                    "Main-Class": "calculator.lang.Main",
                    "Created-By": "Gradle 0.9-preview-1",
                    "Build-Jdk": "1.6.0_17"
    }

    // adds compile dependencies to jar package
    from configurations.compile.collect { it.isDirectory() ? it :
zipTree(it) }
}

Kind Regards,

Chris

PS: If it would be useful, I would be happy to add a cookbook entry
somewhere on using ANTLR3 with gradle. Not sure how I'd do this.



Adam Murdoch-2 wrote:
> 
> 
> 
> On 10/04/10 10:17 PM, chrismolozian wrote:
>> 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
>>    
> 
> Could you run gradle with the -s command-line option, so we can see the 
> stack trace for the failure?
> 
> 
> -- 
> 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-tp28171481p28208185.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


Reply via email to