Gradle Task . “(type: Copy)” and can't both work

task simpleTask{ print("simpleTask is reach"); } task copySomeFile(type: Copy){ print("copySomeFile is reach"); from baseProjectPath; into toProjectPath; appendXML(); } def appendXML(){ //modify a.txt }

//i just want to run "simpleTask" only, but when "gradle simpleTask", the task"copySomeFile" will be run also ! I know beacuse gradle initialization.

but if write like this

task copySomeFile(type: Copy)<<{ }

the "copySomeFile" will not work.

it seems like "(type: Copy)" can't work with the "<<" or "doLast{}"?

i just want "--gradle simpleTask" "--gradle copySomeFile" can run alone.


You have to read about Gradle build lifecycle.

There are 2 phases you should note - Configuration and Execution. All tasks are always been configured on every build, but only some of them are really executed as the Execution phase.

What you see is that copySomeFile task was configured during the configuration phase. It doesn't copy anything, but it has to be configured. And everything within a tasks closure is task's configuration, that is why you see results of the print("copySomeFile is reach"); in the output.

<< or doLast are used to run something at the Execution phase, but your task of type Copy will not be configured if you place all it's configuration into doLast section or add << to the task definition - that is the reason why copy doesn't work.


Yeh, i got it. How much I appreciate both of you. SHARE THE CODE:

task simpleTask { print("\nsimpleTask is configured"); // executed during the configuration plase, always doLast { print("\nsimpleTask is executed"); // executed during the execution plase, only if the simpleTask is executed } } task copySomeFile(type: Copy) { print("\ncopySomeFile is configured"); // executed always,执行其他任务时,此代码也会执行 from "D:/a.txt";// not executed. 执行其他任务时,此代码不会执行 into "D:/b.txt";// not executed. 执行其他任务时,此代码不会执行 doLast { appendXML(); //only this task executed, the appendXML executed. 只有此task执行时,才会执行.比如(gradle copySomeFile); } } def appendXML(){ print("\nappendXML"); }


  • JSF page splitting
  • IOS: error in HomeDirectory
  • How to add these three files properly?“Default.png, Default-568h@2x.png, Default@2x.png” for univers
  • how to stop my php page from continuing when field is empty
  • Dart/Flutter - Flutter - Why ListView is going infinite
  • How to check if a string contains a certain Chinese word in PHP?
  • Kivy Spinner: is any event triggered when a value is selected from the Spinner
  • How to run instrumentation tests for an android library in android studio?
  • Android Studio - Gradle: How to replace variables in a file
  • Generating JAR file with Android Studio and Gradle
  • How to manually add Gradle module to Android project?
  • What is the simplest way to mix Java+Scala in an Android project using Gradle?
  • Run a background job from Gradle
  • App not installed after upgrading to Android - P
  • How can I add custom task to the Eclipse Gradle Task Tab?
  • Failed to resolve: com.google.gms.google-services:15.0.1:
  • How do you Cross Compile to Scala.JS with Gradle
  • 3.0.0.M1 how to run on https connection
  • Reusing the same code across multiple Android Studio projects
  • Specify ivy configuration in gradle dependency
  • adding url to BuildConfig file from Gradle
  • react-native-video [android] undefined is not an object (evaluating NativeModuels.UIManager.RCTVideo
  • Android Studio not working after update 1.3.0
  • Google Cloud Builder - Gradle
  • IE8 stops network access after 5 long polling request
  • Illegal reflective access operation
  • Initialization section of the package
  • MRO with multiple inheritance in python
  • List comprehension with if conditional to get list of files of a specific type
  • aapt.exe'' finished with non-zero exit value 1
  • Android Studio 1.3 RC3. Google Play services out of date. Requires 7571000 but found 6774470
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • How to add date and time under each post in guestbook in google app engine
  • ORA-29908: missing primary invocation for ancillary operator
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?