Skip to content

Intro to Gradle

Posted on:September 23, 2022 at 03:22 PM

Gradle tasks

list default tasks in gradle:

$ gradle tasks

Creating a custom task in gradle (using groovy):

In build.gradle file add following lines:

task myCustomTask {
	group "Custom"
	description "This is a custom task"
	doLast {
		println "Executing custom task"
  	}
}
conditional execution of tasks:
myCustomTask.onlyIf {
project.hasProperty('doOperation')

}

To run it from command line:

$ gradle myCustomTask -P doOperation

Project dependencies Vs external dependencies. Eclipse plugin.
Custom gradle task.
Running custom tasks.
gradle customTaskName.
Copy tasks in gradle.

Types : copy, zip, javadoc etc.
doFirst block
doLast block
How to skip tasks in gradle.

Task dependencies in gradle:

task doSomeOperation1 {
	group "MyCustomTasks"
	doLast{
	println "This is operation 1"
	}
}

task doSomeOperation2(dependsOn: 'doSomeOperation1') {
	group "MyCustomTasks"
	doLast{
	println "This is opeartion 2"
	}
}

How to create zip file using custom gradle task?