How to have Gradle task depend on another task but not re-execute if the other executes?
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
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 taskBnot meet your requirements?
– Lukas Körfer
Nov 10 '18 at 10:33
Indeed, if your only task dependency wastaskA.dependsOn taskB, thentaskAwouldn’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 '18 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 '18 at 16:09
Lukas, thatdependOnwould trigger the execution oftaskAiftaskBwere executed. I don't want that to happen.
– November Yankee
Nov 11 '18 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 '18 at 16:13
|
show 2 more comments
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 '18 at 16:40
November Yankee
asked Nov 9 '18 at 23:25
November YankeeNovember Yankee
7,326155996
7,326155996
Well, at what point doestaskA.dependsOn taskBnot meet your requirements?
– Lukas Körfer
Nov 10 '18 at 10:33
Indeed, if your only task dependency wastaskA.dependsOn taskB, thentaskAwouldn’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 '18 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 '18 at 16:09
Lukas, thatdependOnwould trigger the execution oftaskAiftaskBwere executed. I don't want that to happen.
– November Yankee
Nov 11 '18 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 '18 at 16:13
|
show 2 more comments
Well, at what point doestaskA.dependsOn taskBnot meet your requirements?
– Lukas Körfer
Nov 10 '18 at 10:33
Indeed, if your only task dependency wastaskA.dependsOn taskB, thentaskAwouldn’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 '18 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 '18 at 16:09
Lukas, thatdependOnwould trigger the execution oftaskAiftaskBwere executed. I don't want that to happen.
– November Yankee
Nov 11 '18 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 '18 at 16:13
Well, at what point does
taskA.dependsOn taskB not meet your requirements?– Lukas Körfer
Nov 10 '18 at 10:33
Well, at what point does
taskA.dependsOn taskB not meet your requirements?– Lukas Körfer
Nov 10 '18 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 '18 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 '18 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 '18 at 16:09
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 '18 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 '18 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 '18 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 '18 at 16:13
I've made the question more precise.
– November Yankee
Nov 11 '18 at 16:13
|
show 2 more comments
1 Answer
1
active
oldest
votes
Use onlyIf:
taskB.onlyIf {
trueIffNotCiOrInputsAreNewerThanOutput()
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use onlyIf:
taskB.onlyIf {
trueIffNotCiOrInputsAreNewerThanOutput()
}
add a comment |
Use onlyIf:
taskB.onlyIf {
trueIffNotCiOrInputsAreNewerThanOutput()
}
add a comment |
Use onlyIf:
taskB.onlyIf {
trueIffNotCiOrInputsAreNewerThanOutput()
}
Use onlyIf:
taskB.onlyIf {
trueIffNotCiOrInputsAreNewerThanOutput()
}
answered Nov 13 '18 at 21:39
November YankeeNovember Yankee
7,326155996
7,326155996
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.
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 taskBnot meet your requirements?– Lukas Körfer
Nov 10 '18 at 10:33
Indeed, if your only task dependency was
taskA.dependsOn taskB, thentaskAwouldn’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 '18 at 20:49
Yes, there are other dependencies involved. I'm not seeing why that would matter in this question.
– November Yankee
Nov 11 '18 at 16:09
Lukas, that
dependOnwould trigger the execution oftaskAiftaskBwere executed. I don't want that to happen.– November Yankee
Nov 11 '18 at 16:10
I've made the question more precise.
– November Yankee
Nov 11 '18 at 16:13