This is a hands-on exercise to go along with the Introduction to Gradle Build Tool for Developers training module. In this exercise you will go over the following:
- See available tasks
- Run an application
- Run test task and inspect report
- Add and use external plugin
- Completed the first hands-on exercise
- You can perform the exercises in the same Gradle project used in exercise 1
-
Create a file called
gradle.propertiesin the top level directory -
In it put the line:
org.gradle.console=verbose -
Save the file
This section is specific to using IntelliJ editor. If you don't use IntelliJ you can skip this section.
- Open the Gradle toolbar on right side of the IDE and explore the tasks. Notice
there are tasks under the top level
Tasksas well as underapp. Usually you will want to run the tasks under the specific Gradle project, in this caseapp. Running tasks under the top levelTaskswill run the task for all projects, if there were more than one.
- Close the Gradle toolbar.
-
Open a terminal in the project folder. In IntelliJ you can open the
Terminaltab in the lower toolbar. -
Run
./gradlew :app:tasks --all. Scroll up and explore the tasks.
- In the tasks list, notice the
runtask under theApplication tasksgroup.
- Inspect the file
app/src/main/java/com/gradle/lab/App.java. Notice themainmethod is supposed to print a greeting message.
- Now look at the
applicationblock inbuild.gradle.kts, notice that themainClassis set as the file just viewed.
- In the terminal, execute the
./gradlew :app:runcommand. Notice the greeting message is printed.
- Open the file
app/src/test/java/com/gradle/lab/AppTest.javain the IDE. Notice there is one test defined.
- Open the Gradle toolbar again and open
app/Tasks/verification. Double-click on thetesttask.
- Notice the task run output on the bottom of the IDE.
- Navigate to
app/build/reports/tests/testand open theindex.htmlin a browser.
-
Open the Gradle Plugin Portal page in a browser.
-
Search for
task tree. In the search results notice the information on the right side which indicates when the plugin was last updated. Click on theorg.barfuin.gradle.taskinfoplugin.
- Copy the
idline and paste it into thepluginsection ofbuild.gradle.kts. Notice a popup that appears when you make a change to the Gradle file. Click on the second icon to have the IDE process the changes to the Gradle config.
NOTE: The version you will see may differ than in the screenshot below.
- If using IntelliJ, open the Gradle toolbar and expand
Tasks/other. Notice the 3 taskstiJson,tiOrderandtiTree. These have been added by the plugin. Do not run the tasks yet.
- Go back to the plugin page in the browser. Click on the repository link near the top of the page.
- In the README, notice the author describes how to invoke the tasks. An argument has to be passed, which is the task whose dependencies you want to inspect. Therefore it is easier to run the task in the terminal where you can easily pass arguments.
- Open the terminal. Run
./gradlew :app:tiTree :app:testto see the dependencies for the test task.
If you get stuck you can refer to the project files in this repository.


















