Start build from task


(Jordan Zimmerman) #1

I want to start the build task from a new task I’m creating. How do I do this?


(Luke Daley) #2

I don’t quite understand what you are asking for.


(Jordan Zimmerman) #3

I want to create a new task and have one of the things that the task does be starting a build.


(Jordan Zimmerman) #4
  • bump *

(Luke Daley) #5

Does the org.gradle.api.tasks.GradleBuild task do what you need?


(Jordan Zimmerman) #6

I’m not sure how to use that. I’ve set my task as type GradleBuild but the build doesn’t start.


(Jordan Zimmerman) #7

OK, I think I’ve got it now:

task release(type: GradleBuild) {
    tasks = ['build']
}

(Luke Daley) #8

So is this working for you now Jordan?


(Jordan Zimmerman) #9

Yes - it does what I want. I’m not sure, though, if there’s a better way.


(gradle-shorn) #10

(Gradle newbie here)

I’m curious about Jordan’s solution - does the following snippet do the same thing? (except that the build task would run before the release task)

task release(type: GradleBuild, dependsOn: build) {
}

(Jordan Zimmerman) #11

Shorn - that generates an error. I’m not sure why.


(Luke Daley) #12

Shorn, no they are two different things.

The org.gradle.api.tasks.GradleBuild task is for launching a separate Gradle process during a Gradle build. So if you need to build a completely separate Gradle project from another Gradle project it’s useful.

If you’re trying to create a task named “release” that just triggers the “build” task in the same build, you just need:

task release(dependsOn: build)

Does that explain the difference?


(gradle-shorn) #13

Oh, yes - I see now (I didn’t realise what the GradleBuild task was doing).

Cheers.