3

Can I call to gradle task from groovy script w/o calling gradle (gradlew) script as external program? I.e. put gradle jar to classpath and calling to main?

1
  • Yes, you can surely do it, the only question is how. Maybe it would be good to change your question. Feb 23, 2014 at 12:29

1 Answer 1

6

You can use Gradle Api to execute the task programmatically:

    ProjectConnection connection = GradleConnector.newConnector()
            .forProjectDirectory(projectDir) // the gradle project directory
            .connect()

    connection.newBuild()
                .forTasks(taskName) // set your task name here
                .run()

You need to depend on Gradle Api (the jar as you mentioned):

     "org.gradle:gradle-tooling-api:${gradle.gradleVersion}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.