Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is "task type" in gradle?

Tags:

gradle

I can declare a type for a gradle task and doing so seems to inherit some methods. For example:

task myCopyTask(type: Copy){
  from "foo"
  into "bar"
}

So, I think myCopyTask is an instance of org.gradle.api.tasks.Copy class, yes? And if I declare a task without any type, it is an instance of org.gradle.api.DefaultTask? Sorry for the basic question. I have been reading the gradle guide like this page but it isn't clear to me what type: exactly is.

like image 575
hummingV Avatar asked Dec 28 '16 20:12

hummingV


3 Answers

To get the type of an existing task, you can make use of Gradle's built-in help task using the --task command line option. The --task option takes in a task path for any task in the project. Here is an example using the help task on itself:

# ./gradlew help --task help                               

> Task :help                                        
Detailed task information for help                  

Path                                                
     :help                                          

Type                                                
     Help (org.gradle.configuration.Help)           

Options                                             
     --task     The task to show help for.          

Description                                         
     Displays a help message.                       

Group                                               
     help
like image 67
mkobit Avatar answered Sep 23 '22 08:09

mkobit


Why not just add a println and find out yourself?

task myCopyTask(type: Copy) {
    ... 
}
println "Type is $myCopyTask.class.name"
like image 23
lance-java Avatar answered Sep 23 '22 08:09

lance-java


It's already answered but this might help to understand as well.

They're the subclasses of the type Task. Once you define a type for your task, you get to access/set/configure that particular task's properties. In your case, this is a subclass called "Copy" (as you've already kinda figure out).

Note: Tasks are shipped with various plugins or written by you.

like image 34
stdout Avatar answered Sep 23 '22 08:09

stdout