Using gradle from Java API? (building custom IDE)

Hi! I’m having a bit of a hard time figuring out how to setup Gradle for my program. I am building something similar to an IDE, and I need to use Gradle from my program (Java based) to build Android applications. It would be great if I could use Gradle to setup a new Android project with all the necessary resources and files, plug in a few class files from the project being built, hit build, and get the resulting .apk file.

I don’t if this is possible, but I did read something mentioning Gradle for IDEs. Any help you can offer would be much appreciated! I did look at the JavaDoc, however it is just overwhelming. If I could get some example of using Gradle from Java code to build anything, It would be enough for me to get a handle on this. I know Gradle has ability to build APKs from command line, So if I can figure out how to control Gradle from Java, the rest should be easy.

Thank you!

What you’re looking for is the Tooling API.