How to have Gradle task depend on another task but not re-execute if the other executes?
up vote
1
down vote
favorite
I would like to have one Gradle task, taskA
, to trigger the execution of another task, taskB
, if both aren't up-to-date but the execution of taskB
shouldn't trigger an execution of taskA
if only taskB
isn't up-to-date. How can this be done?
IOW, there are two parts of the task dependency involved here, the task hierarchy and the up-to-date checks. I would like to bed able to set up the task hierarchy but not have it imply the up-to-date check for taskA
.
Context: taskA
must execute if its inputs change or if taskB
executes on a dev machine (ie not CI). taskB
must execute if it's not up-to-date. This is because the output of taskB
is an executable that's run by taskA
. The reason taskA
shouldn't run if only the executable is updated is because the updated executable can produce different output than the previous executable. That new output can cause issues with other parts of the build. Since the purpose of the output is to help ensure users are following best practices, the new output of the updated executable can be ignored in CI builds.
More concretely, taskA
calls a protolock
binary which is output by taskB
. taskA
outputs a proto.lock
file which engineers should commit. Auto-committing that file can lead to surprises for engineers and to subversion of the purpose of these checks.
gradle
|
show 2 more comments
up vote
1
down vote
favorite
I would like to have one Gradle task, taskA
, to trigger the execution of another task, taskB
, if both aren't up-to-date but the execution of taskB
shouldn't trigger an execution of taskA
if only taskB
isn't up-to-date. How can this be done?
IOW, there are two parts of the task dependency involved here, the task hierarchy and the up-to-date checks. I would like to bed able to set up the task hierarchy but not have it imply the up-to-date check for taskA
.
Context: taskA
must execute if its inputs change or if taskB
executes on a dev machine (ie not CI). taskB
must execute if it's not up-to-date. This is because the output of taskB
is an executable that's run by taskA
. The reason taskA
shouldn't run if only the executable is updated is because the updated executable can produce different output than the previous executable. That new output can cause issues with other parts of the build. Since the purpose of the output is to help ensure users are following best practices, the new output of the updated executable can be ignored in CI builds.
More concretely, taskA
calls a protolock
binary which is output by taskB
. taskA
outputs a proto.lock
file which engineers should commit. Auto-committing that file can lead to surprises for engineers and to subversion of the purpose of these checks.
gradle
Well, at what point doestaskA.dependsOn taskB
not meet your requirements?
– Lukas Körfer
Nov 10 at 10:33
Indeed, if your only task dependency wastaskA.dependsOn taskB
, thentaskA
wouldn’t be executed if you rangradle taskB
. If it still does, then there must be more in your build configuration than you have told us.
– Chriki
Nov 10 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 at 16:09
Lukas, thatdependOn
would trigger the execution oftaskA
iftaskB
were executed. I don't want that to happen.
– November Yankee
Nov 11 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 at 16:13
|
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to have one Gradle task, taskA
, to trigger the execution of another task, taskB
, if both aren't up-to-date but the execution of taskB
shouldn't trigger an execution of taskA
if only taskB
isn't up-to-date. How can this be done?
IOW, there are two parts of the task dependency involved here, the task hierarchy and the up-to-date checks. I would like to bed able to set up the task hierarchy but not have it imply the up-to-date check for taskA
.
Context: taskA
must execute if its inputs change or if taskB
executes on a dev machine (ie not CI). taskB
must execute if it's not up-to-date. This is because the output of taskB
is an executable that's run by taskA
. The reason taskA
shouldn't run if only the executable is updated is because the updated executable can produce different output than the previous executable. That new output can cause issues with other parts of the build. Since the purpose of the output is to help ensure users are following best practices, the new output of the updated executable can be ignored in CI builds.
More concretely, taskA
calls a protolock
binary which is output by taskB
. taskA
outputs a proto.lock
file which engineers should commit. Auto-committing that file can lead to surprises for engineers and to subversion of the purpose of these checks.
gradle
I would like to have one Gradle task, taskA
, to trigger the execution of another task, taskB
, if both aren't up-to-date but the execution of taskB
shouldn't trigger an execution of taskA
if only taskB
isn't up-to-date. How can this be done?
IOW, there are two parts of the task dependency involved here, the task hierarchy and the up-to-date checks. I would like to bed able to set up the task hierarchy but not have it imply the up-to-date check for taskA
.
Context: taskA
must execute if its inputs change or if taskB
executes on a dev machine (ie not CI). taskB
must execute if it's not up-to-date. This is because the output of taskB
is an executable that's run by taskA
. The reason taskA
shouldn't run if only the executable is updated is because the updated executable can produce different output than the previous executable. That new output can cause issues with other parts of the build. Since the purpose of the output is to help ensure users are following best practices, the new output of the updated executable can be ignored in CI builds.
More concretely, taskA
calls a protolock
binary which is output by taskB
. taskA
outputs a proto.lock
file which engineers should commit. Auto-committing that file can lead to surprises for engineers and to subversion of the purpose of these checks.
gradle
gradle
edited Nov 12 at 16:40
asked Nov 9 at 23:25
November Yankee
7,271155996
7,271155996
Well, at what point doestaskA.dependsOn taskB
not meet your requirements?
– Lukas Körfer
Nov 10 at 10:33
Indeed, if your only task dependency wastaskA.dependsOn taskB
, thentaskA
wouldn’t be executed if you rangradle taskB
. If it still does, then there must be more in your build configuration than you have told us.
– Chriki
Nov 10 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 at 16:09
Lukas, thatdependOn
would trigger the execution oftaskA
iftaskB
were executed. I don't want that to happen.
– November Yankee
Nov 11 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 at 16:13
|
show 2 more comments
Well, at what point doestaskA.dependsOn taskB
not meet your requirements?
– Lukas Körfer
Nov 10 at 10:33
Indeed, if your only task dependency wastaskA.dependsOn taskB
, thentaskA
wouldn’t be executed if you rangradle taskB
. If it still does, then there must be more in your build configuration than you have told us.
– Chriki
Nov 10 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 at 16:09
Lukas, thatdependOn
would trigger the execution oftaskA
iftaskB
were executed. I don't want that to happen.
– November Yankee
Nov 11 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 at 16:13
Well, at what point does
taskA.dependsOn taskB
not meet your requirements?– Lukas Körfer
Nov 10 at 10:33
Well, at what point does
taskA.dependsOn taskB
not meet your requirements?– Lukas Körfer
Nov 10 at 10:33
Indeed, if your only task dependency was
taskA.dependsOn taskB
, then taskA
wouldn’t be executed if you ran gradle taskB
. If it still does, then there must be more in your build configuration than you have told us.– Chriki
Nov 10 at 20:49
Indeed, if your only task dependency was
taskA.dependsOn taskB
, then taskA
wouldn’t be executed if you ran gradle taskB
. If it still does, then there must be more in your build configuration than you have told us.– Chriki
Nov 10 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 at 16:09
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 at 16:09
Lukas, that
dependOn
would trigger the execution of taskA
if taskB
were executed. I don't want that to happen.– November Yankee
Nov 11 at 16:10
Lukas, that
dependOn
would trigger the execution of taskA
if taskB
were executed. I don't want that to happen.– November Yankee
Nov 11 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 at 16:13
I've made the question more precise.
– November Yankee
Nov 11 at 16:13
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
Use onlyIf
:
taskB.onlyIf
trueIffNotCiOrInputsAreNewerThanOutput()
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Use onlyIf
:
taskB.onlyIf
trueIffNotCiOrInputsAreNewerThanOutput()
add a comment |
up vote
0
down vote
Use onlyIf
:
taskB.onlyIf
trueIffNotCiOrInputsAreNewerThanOutput()
add a comment |
up vote
0
down vote
up vote
0
down vote
Use onlyIf
:
taskB.onlyIf
trueIffNotCiOrInputsAreNewerThanOutput()
Use onlyIf
:
taskB.onlyIf
trueIffNotCiOrInputsAreNewerThanOutput()
answered Nov 13 at 21:39
November Yankee
7,271155996
7,271155996
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234518%2fhow-to-have-gradle-task-depend-on-another-task-but-not-re-execute-if-the-other-e%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Well, at what point does
taskA.dependsOn taskB
not meet your requirements?– Lukas Körfer
Nov 10 at 10:33
Indeed, if your only task dependency was
taskA.dependsOn taskB
, thentaskA
wouldn’t be executed if you rangradle taskB
. If it still does, then there must be more in your build configuration than you have told us.– Chriki
Nov 10 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 at 16:09
Lukas, that
dependOn
would trigger the execution oftaskA
iftaskB
were executed. I don't want that to happen.– November Yankee
Nov 11 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 at 16:13