Integrate JavaCC gradle plugin with Android Studio

I successfully created a very simple cloud project in android studio after in this example . In addition, I added JavaCC support to the project using this gradle plugin . Now I can put my * .jj files in the javacc folder and compile them using the compileJavacc task from android studio. My file build.gradlenow looks like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.14'
        classpath "ca.coglinc:javacc-gradle-plugin:2.0.4"
    }

}

repositories {
    mavenCentral();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
apply plugin: "ca.coglinc.javacc"

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.14'
    compile 'javax.servlet:servlet-api:2.5'
}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
}

Being a newbie to gradle and android studio, I'm not sure how to proceed with the following:

  • Create javaCC created files added to my build path
  • The JavaCC compilation task runs automatically when you modify * .jj files.

How can I solve these two things in the most elegant way?

Thank!

+4
1

, , .

android {
    // ...
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'build/generated/javacc']
        }
    }
    applicationVariants.all { variant ->
        variant.javaCompile.dependsOn.add(compileJavacc)
    }
    // ...
}
+1

All Articles