Running Gradle tasks
There are several convenient ways to run Gradle tasks from IntelliJ IDEA.
We can also click on the elephant at the top of the Gradle tool window to run any Gradle task.
IntelliJ IDEA populates this with common Gradle tasks and ones we've run recently.
This can be a good way to run multiple gradle tasks, like you would from the command line. For example, running
gradle clean build to make sure everything is working as expected before committing changes.
You may have noticed this actually uses the Run Anything dialog, which we can bring up by pressing ⌃⌃ (macOS) / Ctrl+Ctrl (Windows/Linux), then type "gradle" followed by the gradle task name or names.
We can, of course, run Gradle commands from the terminal window inside IntelliJ IDEA. Open this with ⌥F12 (macOS) / Alt+F12 (Windows/Linux).
If we type a Gradle command, IntelliJ IDEA highlights it. This means that this is a command that can be run inside the IDE, it doesn't have to be run from the command line.
If we press ⏎ (macOS) / Enter (Windows/Linux), it will be run from the command line like we expect. If we press ⌘⏎ (macOS) / Ctrl+Enter (Windows/Linux), this command will be run in IntelliJ IDEA. In this case, the Run tool window is opened and the command is run there. We see the results the same way we would have if we'd run the command from the Gradle tool window.
Next, let's look at some tips for working with Gradle in IntelliJ IDEA.