Running tasks in gradle

Now let us see how to run the gradle tasks. Gradle provides very popular plugins that is used in Java projects.
apply plugin: ‘java’

This plugin has definitions for all important gradle tasks. Default tasks in Gradle project We can run any Gradle task by using below command.
gradle taskName

If you have not specified any task, the default task will run. You can specify the default task in build.gradle file using below syntax. So if we issue Gradle command with below line in Build.gradle file, 2 tasks will be executed – task1 and task2
defaultTasks ‘task1’, ‘task2’

Building the project

To build the Gradle project, use below task.
gradle clean build
Above command will store the output in build directory. The compiled classes are stored in build/classes. While Jar files are stored in build/libs Gradle does incremental compiling only. It means if the source is not changes and if you use the build command again, no files will be compiled again.

Executing tests in Gradle project

  • gradle -q test : to run tests. -q means that task will be executed in quite mode
  • gradle build -x test : To build the project but to skip the tests. -x skips any specified task.
Some useful command line switches
  • gradle -b xyz/build.gradle build : to execute the task from other build file
  • gradle -p abcproject build : to build another project
  • gradle build –continue : to continue building the project even if some tasks fail
  • gradle -m build : This command will only show what tasks will be executed. It does not execute any of the tasks.

Web development and Automation testing

solutions delivered!!