androidgradleandroid-gradle-plugingreendaogreendao-generator

Run GreenDao generator automatically everytime I build project with gradle


I'm developing an Android app and I'm using greendao to model my database. I wanted to run the daogenerator everytime I rebuild a project but it is on another module.

How can I do this using gradle?

This is, how can I run the application in a module before building another module.

Thank you.


Solution

  • Sure you can do that!

    1. Create a task that runs your generation. For my case the module with greendao is next to the app module. It is an java module.

      task generateDao(type: GradleBuild) { dir = "../greendaogenerator" tasks = ["run"] }

    2. Configure that this task will run before every compile task

      tasks.whenTaskAdded { task -> if (task.name.startsWith('compile')) { task.dependsOn generateDao task.mustRunAfter generateDao } }