gradle has a build file,typically build.gradle.This contains tasks,plugins,dependencies
example:
build.gradle
-----
task hello{
doLast {
println "Hello, Gradle"
}
}
>gradle hello
In the gradle file add below line,it will add all java related tasks for the gradle and with java folder structure.
apply plugin: 'java'
>gradle tasks -- lists all tasks
>gradle build -- compiles the java code.
a wrapper task example:
apply plugin: 'java'
task wrapper(type: Wrapper){
gradleVersion = '2.6'
}
>gradle wrapper
this creates a gradlew batch file.
gradlew build --> use this instead of normal gradle.so it uses the 2.6 version only.
the 2.6 version is extracted in .gradle folder of user directory.
In this way, we are carrying the version of gradle also along with gradle file.
----
task:
code that gradle executes.
-has a lifecyle.
-has properties
-has 'actions'
-has dependencies
example build file:
-----
project.task("Task1")
>gradle tasks
task("Task2")
task "Task3"
task Task4
>gradle tasks
as project is top level bject, no need to mention it.
to add properties to task:
-----
Task4.description = "Task 4 Description"
>gradle Task4
Task4.doLast {println "This is Task 4"}
Task3 << {println "This is task 3"}
task Task5 << {println "this is task 5"}
Task5 << {println "Another closure"}
>gradle Task5
task Task6{
description "This is task 6"
doLast{
println "This is task 6"
}
}
example:
build.gradle
-----
task hello{
doLast {
println "Hello, Gradle"
}
}
>gradle hello
In the gradle file add below line,it will add all java related tasks for the gradle and with java folder structure.
apply plugin: 'java'
>gradle tasks -- lists all tasks
>gradle build -- compiles the java code.
a wrapper task example:
apply plugin: 'java'
task wrapper(type: Wrapper){
gradleVersion = '2.6'
}
>gradle wrapper
this creates a gradlew batch file.
gradlew build --> use this instead of normal gradle.so it uses the 2.6 version only.
the 2.6 version is extracted in .gradle folder of user directory.
In this way, we are carrying the version of gradle also along with gradle file.
----
task:
code that gradle executes.
-has a lifecyle.
-has properties
-has 'actions'
-has dependencies
example build file:
-----
project.task("Task1")
>gradle tasks
task("Task2")
task "Task3"
task Task4
>gradle tasks
as project is top level bject, no need to mention it.
to add properties to task:
-----
Task4.description = "Task 4 Description"
>gradle Task4
Task4.doLast {println "This is Task 4"}
Task3 << {println "This is task 3"}
task Task5 << {println "this is task 5"}
Task5 << {println "Another closure"}
>gradle Task5
task Task6{
description "This is task 6"
doLast{
println "This is task 6"
}
}
No comments:
Post a Comment