Dynamically created task of type Copy is always UP-TO-DATE












8















I've prepared a very simple script, that illustrates the problem I see using Gradle 1.7 (need to stick with it because of some plugins not yet supporting newer versions).



I'm trying to dynamically create tasks each of which corresponds to a file in the project directory. This works fine, but the tasks I create never get executed as soon as I assign them type 'Copy'.



Here is my problem build.gradle:



file('templates').listFiles().each { File f ->

// THIS LINE DOES NOT WORK
task "myDist-${f.name}" (type: Copy) {

// NEXT LINE WORKS
//task "myDist-${f.name}" {
doLast {
println "MYDIST-" + f.name
}
}
}

task distAll(dependsOn: tasks.matching { Task task -> task.name.startsWith("myDist")}) {
println "MYDISTALL"
}

defaultTasks 'distAll'


in this way my tasks do not get executed when I call default task calling simply gradle:



MYDISTALL
:myDist-template1 UP-TO-DATE
:myDist-template2 UP-TO-DATE
:distAll UP-TO-DATE

BUILD SUCCESSFUL


If I remove type Copy from my dynamic task (uncommenting the line above), my tasks get executed:



MYDISTALL
:myDist-template1
MYDIST-template1
:myDist-template2
MYDIST-template2
:distAll

BUILD SUCCESSFUL


(You'll need to create a folder name templates in the same directory where build.gradle is located and put couple of empty files into there in order to run the test)



According to the debug output:




Skipping task ':myDist-template1' as it has no source files.



Skipping task ':myDist-template2' as it has no source files.




So how can I specify source files and make my Copy tasks execute?
I've tried adding



from( '/absolute/path/to/existing/file' ) {
into 'myfolder'
}


to the task body, I've tried assigning task's inputs.source file('/my/existing/file') with no success.
Could you please advise on how to modify my simple script leaving dynamic task creation and keeping my dynamic tasks of type Copy?



Thank you!



Edit:
All right, this way the task gets called:



file('templates').listFiles().each { File f ->
task "myDist-${f.name}" (type: Copy) {
from f
into 'dist'
doLast {
println "MYDIST-" + f.name
}
}
}


but it looks I must always specify from/into. It doesn't suffice to do that in the doLast{} body.










share|improve this question





























    8















    I've prepared a very simple script, that illustrates the problem I see using Gradle 1.7 (need to stick with it because of some plugins not yet supporting newer versions).



    I'm trying to dynamically create tasks each of which corresponds to a file in the project directory. This works fine, but the tasks I create never get executed as soon as I assign them type 'Copy'.



    Here is my problem build.gradle:



    file('templates').listFiles().each { File f ->

    // THIS LINE DOES NOT WORK
    task "myDist-${f.name}" (type: Copy) {

    // NEXT LINE WORKS
    //task "myDist-${f.name}" {
    doLast {
    println "MYDIST-" + f.name
    }
    }
    }

    task distAll(dependsOn: tasks.matching { Task task -> task.name.startsWith("myDist")}) {
    println "MYDISTALL"
    }

    defaultTasks 'distAll'


    in this way my tasks do not get executed when I call default task calling simply gradle:



    MYDISTALL
    :myDist-template1 UP-TO-DATE
    :myDist-template2 UP-TO-DATE
    :distAll UP-TO-DATE

    BUILD SUCCESSFUL


    If I remove type Copy from my dynamic task (uncommenting the line above), my tasks get executed:



    MYDISTALL
    :myDist-template1
    MYDIST-template1
    :myDist-template2
    MYDIST-template2
    :distAll

    BUILD SUCCESSFUL


    (You'll need to create a folder name templates in the same directory where build.gradle is located and put couple of empty files into there in order to run the test)



    According to the debug output:




    Skipping task ':myDist-template1' as it has no source files.



    Skipping task ':myDist-template2' as it has no source files.




    So how can I specify source files and make my Copy tasks execute?
    I've tried adding



    from( '/absolute/path/to/existing/file' ) {
    into 'myfolder'
    }


    to the task body, I've tried assigning task's inputs.source file('/my/existing/file') with no success.
    Could you please advise on how to modify my simple script leaving dynamic task creation and keeping my dynamic tasks of type Copy?



    Thank you!



    Edit:
    All right, this way the task gets called:



    file('templates').listFiles().each { File f ->
    task "myDist-${f.name}" (type: Copy) {
    from f
    into 'dist'
    doLast {
    println "MYDIST-" + f.name
    }
    }
    }


    but it looks I must always specify from/into. It doesn't suffice to do that in the doLast{} body.










    share|improve this question



























      8












      8








      8


      3






      I've prepared a very simple script, that illustrates the problem I see using Gradle 1.7 (need to stick with it because of some plugins not yet supporting newer versions).



      I'm trying to dynamically create tasks each of which corresponds to a file in the project directory. This works fine, but the tasks I create never get executed as soon as I assign them type 'Copy'.



      Here is my problem build.gradle:



      file('templates').listFiles().each { File f ->

      // THIS LINE DOES NOT WORK
      task "myDist-${f.name}" (type: Copy) {

      // NEXT LINE WORKS
      //task "myDist-${f.name}" {
      doLast {
      println "MYDIST-" + f.name
      }
      }
      }

      task distAll(dependsOn: tasks.matching { Task task -> task.name.startsWith("myDist")}) {
      println "MYDISTALL"
      }

      defaultTasks 'distAll'


      in this way my tasks do not get executed when I call default task calling simply gradle:



      MYDISTALL
      :myDist-template1 UP-TO-DATE
      :myDist-template2 UP-TO-DATE
      :distAll UP-TO-DATE

      BUILD SUCCESSFUL


      If I remove type Copy from my dynamic task (uncommenting the line above), my tasks get executed:



      MYDISTALL
      :myDist-template1
      MYDIST-template1
      :myDist-template2
      MYDIST-template2
      :distAll

      BUILD SUCCESSFUL


      (You'll need to create a folder name templates in the same directory where build.gradle is located and put couple of empty files into there in order to run the test)



      According to the debug output:




      Skipping task ':myDist-template1' as it has no source files.



      Skipping task ':myDist-template2' as it has no source files.




      So how can I specify source files and make my Copy tasks execute?
      I've tried adding



      from( '/absolute/path/to/existing/file' ) {
      into 'myfolder'
      }


      to the task body, I've tried assigning task's inputs.source file('/my/existing/file') with no success.
      Could you please advise on how to modify my simple script leaving dynamic task creation and keeping my dynamic tasks of type Copy?



      Thank you!



      Edit:
      All right, this way the task gets called:



      file('templates').listFiles().each { File f ->
      task "myDist-${f.name}" (type: Copy) {
      from f
      into 'dist'
      doLast {
      println "MYDIST-" + f.name
      }
      }
      }


      but it looks I must always specify from/into. It doesn't suffice to do that in the doLast{} body.










      share|improve this question
















      I've prepared a very simple script, that illustrates the problem I see using Gradle 1.7 (need to stick with it because of some plugins not yet supporting newer versions).



      I'm trying to dynamically create tasks each of which corresponds to a file in the project directory. This works fine, but the tasks I create never get executed as soon as I assign them type 'Copy'.



      Here is my problem build.gradle:



      file('templates').listFiles().each { File f ->

      // THIS LINE DOES NOT WORK
      task "myDist-${f.name}" (type: Copy) {

      // NEXT LINE WORKS
      //task "myDist-${f.name}" {
      doLast {
      println "MYDIST-" + f.name
      }
      }
      }

      task distAll(dependsOn: tasks.matching { Task task -> task.name.startsWith("myDist")}) {
      println "MYDISTALL"
      }

      defaultTasks 'distAll'


      in this way my tasks do not get executed when I call default task calling simply gradle:



      MYDISTALL
      :myDist-template1 UP-TO-DATE
      :myDist-template2 UP-TO-DATE
      :distAll UP-TO-DATE

      BUILD SUCCESSFUL


      If I remove type Copy from my dynamic task (uncommenting the line above), my tasks get executed:



      MYDISTALL
      :myDist-template1
      MYDIST-template1
      :myDist-template2
      MYDIST-template2
      :distAll

      BUILD SUCCESSFUL


      (You'll need to create a folder name templates in the same directory where build.gradle is located and put couple of empty files into there in order to run the test)



      According to the debug output:




      Skipping task ':myDist-template1' as it has no source files.



      Skipping task ':myDist-template2' as it has no source files.




      So how can I specify source files and make my Copy tasks execute?
      I've tried adding



      from( '/absolute/path/to/existing/file' ) {
      into 'myfolder'
      }


      to the task body, I've tried assigning task's inputs.source file('/my/existing/file') with no success.
      Could you please advise on how to modify my simple script leaving dynamic task creation and keeping my dynamic tasks of type Copy?



      Thank you!



      Edit:
      All right, this way the task gets called:



      file('templates').listFiles().each { File f ->
      task "myDist-${f.name}" (type: Copy) {
      from f
      into 'dist'
      doLast {
      println "MYDIST-" + f.name
      }
      }
      }


      but it looks I must always specify from/into. It doesn't suffice to do that in the doLast{} body.







      gradle build.gradle






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '13 at 18:34







      Sergey Shcherbakov

















      asked Nov 27 '13 at 17:30









      Sergey ShcherbakovSergey Shcherbakov

      2,24412435




      2,24412435
























          4 Answers
          4






          active

          oldest

          votes


















          12














          A Copy task only gets executed if it has something to copy. Telling it what to copy is part of configuring the task, and therefore needs to be done in the configuration phase, rather than the execution phase. These are very important concepts to understand, and you can read up on them in the Gradle User Guide or on the Gradle Forums.



          doFirst and doLast blocks get executed in the execution phase, as part of executing the task. Both are too late to tell the task what to copy: doFirst gets executed immediately before the main task action (which in this case is the copying), but (shortly) after the skipped and up-to-date checks (which are based on the task's configuration). doLast gets executed after the main task action, and is therefore clearly too late.






          share|improve this answer


























          • I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

            – Adam
            Mar 9 '17 at 23:17



















          2














          I think the following Gradle User Guide quote answers my question the best:




          Secondly, the copy() method can not honor task dependencies when a task is used as a copy source (i.e. as an argument to from()) because it's a method and not a task. As such, if you are using the copy() method as part of a task action, you must explicitly declare all inputs and outputs in order to get the correct behavior.







          share|improve this answer
























          • That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

            – Peter Niederwieser
            Nov 27 '13 at 22:09













          • Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

            – Sergey Shcherbakov
            Dec 10 '13 at 10:16













          • Not sure what exactly you mean by "I moved copying out of the doLast block".

            – Peter Niederwieser
            Dec 10 '13 at 10:19













          • I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

            – Sergey Shcherbakov
            Dec 10 '13 at 10:27













          • Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

            – Peter Niederwieser
            Dec 10 '13 at 10:37



















          2














          Having read most of the answers to "UP-TO-DATE" Copy tasks in gradle, it appears that the missing part is 'include' keyword:



          task copy3rdPartyLibs(type: Copy) {
          from 'src/main/jni/libs/'
          into 'src/main/libs/armeabi/'
          include '**/*.so'
          }





          share|improve this answer































            0














            Putting from and into as part of the doLast section does not work. An example of a working task definitions is:



            task copyMyFile(type: Copy) {

            def dockerFile = 'src/main/docker/Dockerfile'
            def copyTo = 'build/docker'

            from dockerFile
            into copyTo

            doLast {
            println "Copied Docker file [$dockerFile] to [$copyTo]"
            }
            }


            Not the behavior I was expecting.
            Using gradle 3.2.1






            share|improve this answer


























            • Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

              – Gabriel Kohen
              Apr 4 '18 at 21:38













            • I did, updated it, thanks!

              – Miguel Reyes
              Nov 14 '18 at 19:56











            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20249194%2fdynamically-created-task-of-type-copy-is-always-up-to-date%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            12














            A Copy task only gets executed if it has something to copy. Telling it what to copy is part of configuring the task, and therefore needs to be done in the configuration phase, rather than the execution phase. These are very important concepts to understand, and you can read up on them in the Gradle User Guide or on the Gradle Forums.



            doFirst and doLast blocks get executed in the execution phase, as part of executing the task. Both are too late to tell the task what to copy: doFirst gets executed immediately before the main task action (which in this case is the copying), but (shortly) after the skipped and up-to-date checks (which are based on the task's configuration). doLast gets executed after the main task action, and is therefore clearly too late.






            share|improve this answer


























            • I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

              – Adam
              Mar 9 '17 at 23:17
















            12














            A Copy task only gets executed if it has something to copy. Telling it what to copy is part of configuring the task, and therefore needs to be done in the configuration phase, rather than the execution phase. These are very important concepts to understand, and you can read up on them in the Gradle User Guide or on the Gradle Forums.



            doFirst and doLast blocks get executed in the execution phase, as part of executing the task. Both are too late to tell the task what to copy: doFirst gets executed immediately before the main task action (which in this case is the copying), but (shortly) after the skipped and up-to-date checks (which are based on the task's configuration). doLast gets executed after the main task action, and is therefore clearly too late.






            share|improve this answer


























            • I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

              – Adam
              Mar 9 '17 at 23:17














            12












            12








            12







            A Copy task only gets executed if it has something to copy. Telling it what to copy is part of configuring the task, and therefore needs to be done in the configuration phase, rather than the execution phase. These are very important concepts to understand, and you can read up on them in the Gradle User Guide or on the Gradle Forums.



            doFirst and doLast blocks get executed in the execution phase, as part of executing the task. Both are too late to tell the task what to copy: doFirst gets executed immediately before the main task action (which in this case is the copying), but (shortly) after the skipped and up-to-date checks (which are based on the task's configuration). doLast gets executed after the main task action, and is therefore clearly too late.






            share|improve this answer















            A Copy task only gets executed if it has something to copy. Telling it what to copy is part of configuring the task, and therefore needs to be done in the configuration phase, rather than the execution phase. These are very important concepts to understand, and you can read up on them in the Gradle User Guide or on the Gradle Forums.



            doFirst and doLast blocks get executed in the execution phase, as part of executing the task. Both are too late to tell the task what to copy: doFirst gets executed immediately before the main task action (which in this case is the copying), but (shortly) after the skipped and up-to-date checks (which are based on the task's configuration). doLast gets executed after the main task action, and is therefore clearly too late.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 27 '13 at 22:15

























            answered Nov 27 '13 at 22:08









            Peter NiederwieserPeter Niederwieser

            96.2k15252215




            96.2k15252215













            • I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

              – Adam
              Mar 9 '17 at 23:17



















            • I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

              – Adam
              Mar 9 '17 at 23:17

















            I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

            – Adam
            Mar 9 '17 at 23:17





            I'm telling the copy task what folder it needs to copy at configuration time (the folder is empty at configuration time). By the time the task gets around to copying the folder at execution time another task has executed and copied the file I need into the source directory. Seems to be working.

            – Adam
            Mar 9 '17 at 23:17













            2














            I think the following Gradle User Guide quote answers my question the best:




            Secondly, the copy() method can not honor task dependencies when a task is used as a copy source (i.e. as an argument to from()) because it's a method and not a task. As such, if you are using the copy() method as part of a task action, you must explicitly declare all inputs and outputs in order to get the correct behavior.







            share|improve this answer
























            • That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

              – Peter Niederwieser
              Nov 27 '13 at 22:09













            • Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

              – Sergey Shcherbakov
              Dec 10 '13 at 10:16













            • Not sure what exactly you mean by "I moved copying out of the doLast block".

              – Peter Niederwieser
              Dec 10 '13 at 10:19













            • I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

              – Sergey Shcherbakov
              Dec 10 '13 at 10:27













            • Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

              – Peter Niederwieser
              Dec 10 '13 at 10:37
















            2














            I think the following Gradle User Guide quote answers my question the best:




            Secondly, the copy() method can not honor task dependencies when a task is used as a copy source (i.e. as an argument to from()) because it's a method and not a task. As such, if you are using the copy() method as part of a task action, you must explicitly declare all inputs and outputs in order to get the correct behavior.







            share|improve this answer
























            • That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

              – Peter Niederwieser
              Nov 27 '13 at 22:09













            • Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

              – Sergey Shcherbakov
              Dec 10 '13 at 10:16













            • Not sure what exactly you mean by "I moved copying out of the doLast block".

              – Peter Niederwieser
              Dec 10 '13 at 10:19













            • I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

              – Sergey Shcherbakov
              Dec 10 '13 at 10:27













            • Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

              – Peter Niederwieser
              Dec 10 '13 at 10:37














            2












            2








            2







            I think the following Gradle User Guide quote answers my question the best:




            Secondly, the copy() method can not honor task dependencies when a task is used as a copy source (i.e. as an argument to from()) because it's a method and not a task. As such, if you are using the copy() method as part of a task action, you must explicitly declare all inputs and outputs in order to get the correct behavior.







            share|improve this answer













            I think the following Gradle User Guide quote answers my question the best:




            Secondly, the copy() method can not honor task dependencies when a task is used as a copy source (i.e. as an argument to from()) because it's a method and not a task. As such, if you are using the copy() method as part of a task action, you must explicitly declare all inputs and outputs in order to get the correct behavior.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 27 '13 at 19:05









            Sergey ShcherbakovSergey Shcherbakov

            2,24412435




            2,24412435













            • That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

              – Peter Niederwieser
              Nov 27 '13 at 22:09













            • Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

              – Sergey Shcherbakov
              Dec 10 '13 at 10:16













            • Not sure what exactly you mean by "I moved copying out of the doLast block".

              – Peter Niederwieser
              Dec 10 '13 at 10:19













            • I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

              – Sergey Shcherbakov
              Dec 10 '13 at 10:27













            • Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

              – Peter Niederwieser
              Dec 10 '13 at 10:37



















            • That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

              – Peter Niederwieser
              Nov 27 '13 at 22:09













            • Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

              – Sergey Shcherbakov
              Dec 10 '13 at 10:16













            • Not sure what exactly you mean by "I moved copying out of the doLast block".

              – Peter Niederwieser
              Dec 10 '13 at 10:19













            • I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

              – Sergey Shcherbakov
              Dec 10 '13 at 10:27













            • Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

              – Peter Niederwieser
              Dec 10 '13 at 10:37

















            That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

            – Peter Niederwieser
            Nov 27 '13 at 22:09







            That paragraph talks about the project.copy method and its drawbacks over the Copy task. It isn't related to your problem.

            – Peter Niederwieser
            Nov 27 '13 at 22:09















            Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

            – Sergey Shcherbakov
            Dec 10 '13 at 10:16







            Well.. it actually is related. Since my real problem was that I was trying to copy in the doLast block of a 'Copy' task (the example I've provided doesn't contain that and is oversimplified) and the task was not triggered because of the missing input sources definition. I moved copying out of the doLast block and 'm happy at the moment :) Thanks for the help!

            – Sergey Shcherbakov
            Dec 10 '13 at 10:16















            Not sure what exactly you mean by "I moved copying out of the doLast block".

            – Peter Niederwieser
            Dec 10 '13 at 10:19







            Not sure what exactly you mean by "I moved copying out of the doLast block".

            – Peter Niederwieser
            Dec 10 '13 at 10:19















            I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

            – Sergey Shcherbakov
            Dec 10 '13 at 10:27







            I actually use the gradle RPM plugin (which provides a task of type Copy) and instead of task "distRpm${templ}" (type: Rpm, dependsOn: xxx) { from ... into ... had task "distRpm${templ}" (type: Rpm, dependsOn: xxx) << { from ... into ... (that's what I called 'moved out')

            – Sergey Shcherbakov
            Dec 10 '13 at 10:27















            Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

            – Peter Niederwieser
            Dec 10 '13 at 10:37





            Your old code was configuring the task in a doLast action, which, as I've explained, is too late. (This has nothing to do with the project.copy method.) Now you are configuring the task in the configuration phase, which is correct.

            – Peter Niederwieser
            Dec 10 '13 at 10:37











            2














            Having read most of the answers to "UP-TO-DATE" Copy tasks in gradle, it appears that the missing part is 'include' keyword:



            task copy3rdPartyLibs(type: Copy) {
            from 'src/main/jni/libs/'
            into 'src/main/libs/armeabi/'
            include '**/*.so'
            }





            share|improve this answer




























              2














              Having read most of the answers to "UP-TO-DATE" Copy tasks in gradle, it appears that the missing part is 'include' keyword:



              task copy3rdPartyLibs(type: Copy) {
              from 'src/main/jni/libs/'
              into 'src/main/libs/armeabi/'
              include '**/*.so'
              }





              share|improve this answer


























                2












                2








                2







                Having read most of the answers to "UP-TO-DATE" Copy tasks in gradle, it appears that the missing part is 'include' keyword:



                task copy3rdPartyLibs(type: Copy) {
                from 'src/main/jni/libs/'
                into 'src/main/libs/armeabi/'
                include '**/*.so'
                }





                share|improve this answer













                Having read most of the answers to "UP-TO-DATE" Copy tasks in gradle, it appears that the missing part is 'include' keyword:



                task copy3rdPartyLibs(type: Copy) {
                from 'src/main/jni/libs/'
                into 'src/main/libs/armeabi/'
                include '**/*.so'
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 23 '16 at 17:50









                ToshaTosha

                693519




                693519























                    0














                    Putting from and into as part of the doLast section does not work. An example of a working task definitions is:



                    task copyMyFile(type: Copy) {

                    def dockerFile = 'src/main/docker/Dockerfile'
                    def copyTo = 'build/docker'

                    from dockerFile
                    into copyTo

                    doLast {
                    println "Copied Docker file [$dockerFile] to [$copyTo]"
                    }
                    }


                    Not the behavior I was expecting.
                    Using gradle 3.2.1






                    share|improve this answer


























                    • Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

                      – Gabriel Kohen
                      Apr 4 '18 at 21:38













                    • I did, updated it, thanks!

                      – Miguel Reyes
                      Nov 14 '18 at 19:56
















                    0














                    Putting from and into as part of the doLast section does not work. An example of a working task definitions is:



                    task copyMyFile(type: Copy) {

                    def dockerFile = 'src/main/docker/Dockerfile'
                    def copyTo = 'build/docker'

                    from dockerFile
                    into copyTo

                    doLast {
                    println "Copied Docker file [$dockerFile] to [$copyTo]"
                    }
                    }


                    Not the behavior I was expecting.
                    Using gradle 3.2.1






                    share|improve this answer


























                    • Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

                      – Gabriel Kohen
                      Apr 4 '18 at 21:38













                    • I did, updated it, thanks!

                      – Miguel Reyes
                      Nov 14 '18 at 19:56














                    0












                    0








                    0







                    Putting from and into as part of the doLast section does not work. An example of a working task definitions is:



                    task copyMyFile(type: Copy) {

                    def dockerFile = 'src/main/docker/Dockerfile'
                    def copyTo = 'build/docker'

                    from dockerFile
                    into copyTo

                    doLast {
                    println "Copied Docker file [$dockerFile] to [$copyTo]"
                    }
                    }


                    Not the behavior I was expecting.
                    Using gradle 3.2.1






                    share|improve this answer















                    Putting from and into as part of the doLast section does not work. An example of a working task definitions is:



                    task copyMyFile(type: Copy) {

                    def dockerFile = 'src/main/docker/Dockerfile'
                    def copyTo = 'build/docker'

                    from dockerFile
                    into copyTo

                    doLast {
                    println "Copied Docker file [$dockerFile] to [$copyTo]"
                    }
                    }


                    Not the behavior I was expecting.
                    Using gradle 3.2.1







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 14 '18 at 19:56

























                    answered Dec 1 '16 at 18:08









                    Miguel ReyesMiguel Reyes

                    88689




                    88689













                    • Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

                      – Gabriel Kohen
                      Apr 4 '18 at 21:38













                    • I did, updated it, thanks!

                      – Miguel Reyes
                      Nov 14 '18 at 19:56



















                    • Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

                      – Gabriel Kohen
                      Apr 4 '18 at 21:38













                    • I did, updated it, thanks!

                      – Miguel Reyes
                      Nov 14 '18 at 19:56

















                    Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

                    – Gabriel Kohen
                    Apr 4 '18 at 21:38







                    Did you mean def dockerFile = 'src/main/docker/Dockerfile' ?

                    – Gabriel Kohen
                    Apr 4 '18 at 21:38















                    I did, updated it, thanks!

                    – Miguel Reyes
                    Nov 14 '18 at 19:56





                    I did, updated it, thanks!

                    – Miguel Reyes
                    Nov 14 '18 at 19:56


















                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20249194%2fdynamically-created-task-of-type-copy-is-always-up-to-date%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

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues