Execute gradle task from Java code

Hello,

I wanted to execute one gradle task from Java code of android studio plugin code.

Anyone can help me by providing API’s name or code snippet to execute task from java code.

Thanks,
Sumeet Guha.

The main class is org.gradle.launcher.GradleMain

Not getting your points… can you please provide me code snippet to perform task execution from Android studio plugin java code, where I have created one custom task to generate report, and then later on trying to execute the same task.

You must include the gradle libraries manually into your project, as I couldn’t get it from mvn repositories

class LaunchTest {

    private LaunchTest(){}

    static void main(String[] args) throws Exception {
        // to execute Jar tasks like: gradle jar
        String[] argss = ['--project-dir','/myWorkspace/myProject/myModule,'jar'] as String[]
        org.gradle.launcher.GradleMain.main(argss)
    }
}

Other way is to open a command line inside your Java application and execute gradle jar directly

Hope that helps