Now that we have an application project with a main class, we can use Gradle directly without using NetBeans. Gradle is a command line application, so you will need to use the terminal:
Open your project folder in the file manager. The easiest way to do this is using <
Open in File Manager">> .In the file manager, right click the background and select <
>.Enter the following into the terminal:
gradle run
You will see the 'hello world' message appear in the terminal.
Gradle is smart enough to know that it needs to first compile the code before running it, but only if necessary (Gradle will try to avoid compiling code has already been compiled and has not changed). Run the command again, but this time we will get it to tell us exactly what is going on by using the -info
option:
gradle -info run
You will see that the :compileJava
task is UP-TO-DATE
, meaning that it does not need to compile the classes to run the application.
Let's clean the project to remove the compiled classes:
gradle clean
Build the project again:
gradle -info run
This time you will see that the :compileJava
task is not up to date, so Gradle will compile the classes before running the project.
Enter exit
to exit the terminal.
Note that NetBeans was not involved here at all — we were interacting directly with the build tool (Gradle), rather than getting NetBeans to do that for us.
Hopefully you can see now why build tools like Gradle are very useful. You can use any IDE (assuming it has Gradle support, which it almost certainly will), or if you are one of those stubborn masochists who refuses to give up your favourite text editor (Vim and Emacs are both installed on the lab machines btw) you can perform all build operations from the command line.
If you are struggling to see the benefits — think team development. If you use Gradle projects then each team member can use their preferred IDE or editor without forcing their preferences on other team members.