Ordering Gradle Tasks With finalizedBy and dependsOn











up vote
0
down vote

favorite












I have following setup:



task A {
// config for task C
}

task B {
// config for task C
}

task D {
}


Both of these tasks need to be finalized by the task C with the configuration they provided, and B must execute after A. I have adapted then to following



A.finalizedBy C
B.finalizedBy C
B.mustRunAfter A
D.dependsOn A, B


The issue I'm having with this setup is that when I run gradle D:




  • Task A is executed, configures task C

  • Task B sees that A is finished and executes. B overrides the configuration
    of C.

  • C is only executed for B and not A.


Is there a way to execute a task multiple times? I would need this ordering A -> C -> B -> C.



EDIT:



Following seems to work, but this is not the path I want to take:



task A {
// config for task C
C.execute()
}

task B {
// config for task C
C.execute()
}









share|improve this question




















  • 2




    could you clarified two strange things in your question: 1) you say that when you run gradle A , Gradle executes task B : it should not.. there is nothing in your setup that should trigger execution of B when A is executed. 2) normally a task (here , C) will be executed only once, as explained in this answer discuss.gradle.org/t/… => how did you manage to make task C executed twice?
    – M.Ricciuti
    Nov 22 at 11:03










  • 1. Thank you for the hint. I forgot to mention that B must run after A. 2. I could be wrong. I thought that it's run 2 times, but as you say, it seems to be only once.
    – aarnaut
    Nov 22 at 11:04












  • for 1: B.mustRunAfter A means that when both tasks A and B are executed, B must run after A (see documentation here : docs.gradle.org/current/userguide/…): again, if you execute gradle A, there is no reason that task B is executed.
    – M.Ricciuti
    Nov 22 at 11:20










  • I've update the question. Should be ok now.
    – aarnaut
    Nov 22 at 11:33










  • can you describe more precisly what is task C doing? do you really need to make this job as a Gradle Task ? (maybe you can implement this job as a function/method, invoked by both tasks A and B). I don't think you will manage to make this task C executed twice in a "proper" way (without using C.execute() , which is deprecated / not recommanded
    – M.Ricciuti
    Nov 22 at 11:35















up vote
0
down vote

favorite












I have following setup:



task A {
// config for task C
}

task B {
// config for task C
}

task D {
}


Both of these tasks need to be finalized by the task C with the configuration they provided, and B must execute after A. I have adapted then to following



A.finalizedBy C
B.finalizedBy C
B.mustRunAfter A
D.dependsOn A, B


The issue I'm having with this setup is that when I run gradle D:




  • Task A is executed, configures task C

  • Task B sees that A is finished and executes. B overrides the configuration
    of C.

  • C is only executed for B and not A.


Is there a way to execute a task multiple times? I would need this ordering A -> C -> B -> C.



EDIT:



Following seems to work, but this is not the path I want to take:



task A {
// config for task C
C.execute()
}

task B {
// config for task C
C.execute()
}









share|improve this question




















  • 2




    could you clarified two strange things in your question: 1) you say that when you run gradle A , Gradle executes task B : it should not.. there is nothing in your setup that should trigger execution of B when A is executed. 2) normally a task (here , C) will be executed only once, as explained in this answer discuss.gradle.org/t/… => how did you manage to make task C executed twice?
    – M.Ricciuti
    Nov 22 at 11:03










  • 1. Thank you for the hint. I forgot to mention that B must run after A. 2. I could be wrong. I thought that it's run 2 times, but as you say, it seems to be only once.
    – aarnaut
    Nov 22 at 11:04












  • for 1: B.mustRunAfter A means that when both tasks A and B are executed, B must run after A (see documentation here : docs.gradle.org/current/userguide/…): again, if you execute gradle A, there is no reason that task B is executed.
    – M.Ricciuti
    Nov 22 at 11:20










  • I've update the question. Should be ok now.
    – aarnaut
    Nov 22 at 11:33










  • can you describe more precisly what is task C doing? do you really need to make this job as a Gradle Task ? (maybe you can implement this job as a function/method, invoked by both tasks A and B). I don't think you will manage to make this task C executed twice in a "proper" way (without using C.execute() , which is deprecated / not recommanded
    – M.Ricciuti
    Nov 22 at 11:35













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have following setup:



task A {
// config for task C
}

task B {
// config for task C
}

task D {
}


Both of these tasks need to be finalized by the task C with the configuration they provided, and B must execute after A. I have adapted then to following



A.finalizedBy C
B.finalizedBy C
B.mustRunAfter A
D.dependsOn A, B


The issue I'm having with this setup is that when I run gradle D:




  • Task A is executed, configures task C

  • Task B sees that A is finished and executes. B overrides the configuration
    of C.

  • C is only executed for B and not A.


Is there a way to execute a task multiple times? I would need this ordering A -> C -> B -> C.



EDIT:



Following seems to work, but this is not the path I want to take:



task A {
// config for task C
C.execute()
}

task B {
// config for task C
C.execute()
}









share|improve this question















I have following setup:



task A {
// config for task C
}

task B {
// config for task C
}

task D {
}


Both of these tasks need to be finalized by the task C with the configuration they provided, and B must execute after A. I have adapted then to following



A.finalizedBy C
B.finalizedBy C
B.mustRunAfter A
D.dependsOn A, B


The issue I'm having with this setup is that when I run gradle D:




  • Task A is executed, configures task C

  • Task B sees that A is finished and executes. B overrides the configuration
    of C.

  • C is only executed for B and not A.


Is there a way to execute a task multiple times? I would need this ordering A -> C -> B -> C.



EDIT:



Following seems to work, but this is not the path I want to take:



task A {
// config for task C
C.execute()
}

task B {
// config for task C
C.execute()
}






android gradle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 11:32

























asked Nov 22 at 10:44









aarnaut

153112




153112








  • 2




    could you clarified two strange things in your question: 1) you say that when you run gradle A , Gradle executes task B : it should not.. there is nothing in your setup that should trigger execution of B when A is executed. 2) normally a task (here , C) will be executed only once, as explained in this answer discuss.gradle.org/t/… => how did you manage to make task C executed twice?
    – M.Ricciuti
    Nov 22 at 11:03










  • 1. Thank you for the hint. I forgot to mention that B must run after A. 2. I could be wrong. I thought that it's run 2 times, but as you say, it seems to be only once.
    – aarnaut
    Nov 22 at 11:04












  • for 1: B.mustRunAfter A means that when both tasks A and B are executed, B must run after A (see documentation here : docs.gradle.org/current/userguide/…): again, if you execute gradle A, there is no reason that task B is executed.
    – M.Ricciuti
    Nov 22 at 11:20










  • I've update the question. Should be ok now.
    – aarnaut
    Nov 22 at 11:33










  • can you describe more precisly what is task C doing? do you really need to make this job as a Gradle Task ? (maybe you can implement this job as a function/method, invoked by both tasks A and B). I don't think you will manage to make this task C executed twice in a "proper" way (without using C.execute() , which is deprecated / not recommanded
    – M.Ricciuti
    Nov 22 at 11:35














  • 2




    could you clarified two strange things in your question: 1) you say that when you run gradle A , Gradle executes task B : it should not.. there is nothing in your setup that should trigger execution of B when A is executed. 2) normally a task (here , C) will be executed only once, as explained in this answer discuss.gradle.org/t/… => how did you manage to make task C executed twice?
    – M.Ricciuti
    Nov 22 at 11:03










  • 1. Thank you for the hint. I forgot to mention that B must run after A. 2. I could be wrong. I thought that it's run 2 times, but as you say, it seems to be only once.
    – aarnaut
    Nov 22 at 11:04












  • for 1: B.mustRunAfter A means that when both tasks A and B are executed, B must run after A (see documentation here : docs.gradle.org/current/userguide/…): again, if you execute gradle A, there is no reason that task B is executed.
    – M.Ricciuti
    Nov 22 at 11:20










  • I've update the question. Should be ok now.
    – aarnaut
    Nov 22 at 11:33










  • can you describe more precisly what is task C doing? do you really need to make this job as a Gradle Task ? (maybe you can implement this job as a function/method, invoked by both tasks A and B). I don't think you will manage to make this task C executed twice in a "proper" way (without using C.execute() , which is deprecated / not recommanded
    – M.Ricciuti
    Nov 22 at 11:35








2




2




could you clarified two strange things in your question: 1) you say that when you run gradle A , Gradle executes task B : it should not.. there is nothing in your setup that should trigger execution of B when A is executed. 2) normally a task (here , C) will be executed only once, as explained in this answer discuss.gradle.org/t/… => how did you manage to make task C executed twice?
– M.Ricciuti
Nov 22 at 11:03




could you clarified two strange things in your question: 1) you say that when you run gradle A , Gradle executes task B : it should not.. there is nothing in your setup that should trigger execution of B when A is executed. 2) normally a task (here , C) will be executed only once, as explained in this answer discuss.gradle.org/t/… => how did you manage to make task C executed twice?
– M.Ricciuti
Nov 22 at 11:03












1. Thank you for the hint. I forgot to mention that B must run after A. 2. I could be wrong. I thought that it's run 2 times, but as you say, it seems to be only once.
– aarnaut
Nov 22 at 11:04






1. Thank you for the hint. I forgot to mention that B must run after A. 2. I could be wrong. I thought that it's run 2 times, but as you say, it seems to be only once.
– aarnaut
Nov 22 at 11:04














for 1: B.mustRunAfter A means that when both tasks A and B are executed, B must run after A (see documentation here : docs.gradle.org/current/userguide/…): again, if you execute gradle A, there is no reason that task B is executed.
– M.Ricciuti
Nov 22 at 11:20




for 1: B.mustRunAfter A means that when both tasks A and B are executed, B must run after A (see documentation here : docs.gradle.org/current/userguide/…): again, if you execute gradle A, there is no reason that task B is executed.
– M.Ricciuti
Nov 22 at 11:20












I've update the question. Should be ok now.
– aarnaut
Nov 22 at 11:33




I've update the question. Should be ok now.
– aarnaut
Nov 22 at 11:33












can you describe more precisly what is task C doing? do you really need to make this job as a Gradle Task ? (maybe you can implement this job as a function/method, invoked by both tasks A and B). I don't think you will manage to make this task C executed twice in a "proper" way (without using C.execute() , which is deprecated / not recommanded
– M.Ricciuti
Nov 22 at 11:35




can you describe more precisly what is task C doing? do you really need to make this job as a Gradle Task ? (maybe you can implement this job as a function/method, invoked by both tasks A and B). I don't think you will manage to make this task C executed twice in a "proper" way (without using C.execute() , which is deprecated / not recommanded
– M.Ricciuti
Nov 22 at 11:35












1 Answer
1






active

oldest

votes

















up vote
0
down vote













By design, Gradle will execute a given task only once during a build.



If you have to do two things, although very similar, then you need two tasks.



The concept of task rules might help you solve that issue in a generic fashion.






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%2f53429168%2fordering-gradle-tasks-with-finalizedby-and-dependson%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













    By design, Gradle will execute a given task only once during a build.



    If you have to do two things, although very similar, then you need two tasks.



    The concept of task rules might help you solve that issue in a generic fashion.






    share|improve this answer

























      up vote
      0
      down vote













      By design, Gradle will execute a given task only once during a build.



      If you have to do two things, although very similar, then you need two tasks.



      The concept of task rules might help you solve that issue in a generic fashion.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        By design, Gradle will execute a given task only once during a build.



        If you have to do two things, although very similar, then you need two tasks.



        The concept of task rules might help you solve that issue in a generic fashion.






        share|improve this answer












        By design, Gradle will execute a given task only once during a build.



        If you have to do two things, although very similar, then you need two tasks.



        The concept of task rules might help you solve that issue in a generic fashion.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 9:23









        Louis Jacomet

        6,48621623




        6,48621623






























            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%2f53429168%2fordering-gradle-tasks-with-finalizedby-and-dependson%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)