0

Hi, I'm almost new at Gradle in Android. So.. I'm leanring the Gradle but there are many things that I don't understand.

task clean(type: Delete) {
    println "task clean~~"
    delete rootProject.buildDir
}

In project A when I input "gradlew" in Android Studio Terminal, I can see below result.

C:\Users\xxxx\AndroidStudioProjects\ProjectA>gradlew

> Configure project :
task clean~~

(..snip..)

I have questions:

  1. Why is the task clean executed?
  2. Is it default task?

I couldn't find something like below code in the project's gradle file.

defaultTasks 'clean', 'run' .

  1. What is type in task? (I saw type "Copy" too) .
mazend
  • 456
  • 1
  • 7
  • 37

1 Answers1

0

Well task clean is a default task of gradle. It runs every time you start your android studio. To know the working of gradle you should read this gradle documentation which will surely help you in your questions: Gradle Docs

And for the second point according to gradle documentation: A Task represents a single atomic piece of work for a build, such as compiling classes or generating javadoc. So actually it's a task not type, type is a general term and to be specific task type belongs to central types which are used in Gradle scripts. If you go through the documentation you will also find the type:Copy too.

Umair
  • 6,366
  • 15
  • 42
  • 50
  • I already visited the site before asking the questions but the gradle decumentation is too ambigious to me. Why do we define some task as 'task clean(type: Delete) {}' instead of 'task clean{}'?(without type: Delete) What's the difference between them? – mazend Dec 06 '17 at 07:00
  • @mazend when we define as task:clean(type:Delete) that means we are cleaning the project and also deleting a file (I guess it deletes the build files and create them again on success build). Take a look at this question it might give you the idea. https://stackoverflow.com/questions/29813189/how-do-i-extend-gradles-clean-task-to-delete-a-file – Umair Dec 06 '17 at 07:11
  • and also the clean task is introduced by base plugin that's why we use apply plugin:base in our gradle files. – Umair Dec 06 '17 at 07:13