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?
2
votes
1 Answers
6
votes
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}"