Execute gradle task from Java code

android
plugins

(sumeet) #1

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.


(obesga tirant) #2

The main class is org.gradle.launcher.GradleMain


(sumeet) #3

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.


(obesga tirant) #4

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