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.










share|improve this question























  • 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










  • 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










  • I've made the question more precise.
    – November Yankee
    Nov 11 at 16:13














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.










share|improve this question























  • 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










  • 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










  • I've made the question more precise.
    – November Yankee
    Nov 11 at 16:13












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 16:40

























asked Nov 9 at 23:25









November Yankee

7,271155996




7,271155996











  • 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










  • 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










  • 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










  • 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










  • 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















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












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Use onlyIf:



taskB.onlyIf 
trueIffNotCiOrInputsAreNewerThanOutput()






share|improve this answer




















    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',
    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
    );



    );













    draft saved

    draft discarded


















    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








    up vote
    0
    down vote













    Use onlyIf:



    taskB.onlyIf 
    trueIffNotCiOrInputsAreNewerThanOutput()






    share|improve this answer
























      up vote
      0
      down vote













      Use onlyIf:



      taskB.onlyIf 
      trueIffNotCiOrInputsAreNewerThanOutput()






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Use onlyIf:



        taskB.onlyIf 
        trueIffNotCiOrInputsAreNewerThanOutput()






        share|improve this answer












        Use onlyIf:



        taskB.onlyIf 
        trueIffNotCiOrInputsAreNewerThanOutput()







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 21:39









        November Yankee

        7,271155996




        7,271155996



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党