Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate JavaCC gradle plugin with Android Studio

I have successfully set up a very basic cloud project in android studio following this example. Further, I have added JavaCC support to the project using this gradle plugin. I can now put my *.jj files in the javacc folder and have them compiled by using the compileJavacc task from within android studio. My build.gradle file now 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 gradle and android studio beginner, I am not sure how to continue with the following:

  1. Have the files generated by javaCC added to my build path
  2. Having the JavaCC compile task run automatically when the *.jj files change.

How would I solve those two things in the most elegant way?

Thanks!

like image 857
Lennart Rolland Avatar asked Nov 01 '22 11:11

Lennart Rolland


1 Answers

Facing exactly the same problem and experimenting with different solutions, I've chosen the one shown below.

android {
    // ...
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'build/generated/javacc']
        }
    }
    applicationVariants.all { variant ->
        variant.javaCompile.dependsOn.add(compileJavacc)
    }
    // ...
}
like image 195
Y2i Avatar answered Dec 12 '22 20:12

Y2i