Clean before running a Spring Boot application in IntelliJ Idea

My teammate has faced an issue when running our SpringBoot application in IntelliJ Idea: there were certain Gradle artifacts cached between switching the branches, which prevented the application from running. The issue is easily solved by running clean Gradle task. But my teammate was running it using IntelliJ's UI. And by default, it does not do a clean build before running - just the normal build, if the files have changed.

The solution was a bit of UI trickery.

In the run menu, edit the run configuration (from the meatball menu):

From the run configuration window, click the "Modify options" link:

In the "Before launch" section of a very long drop-down menu, click the "Add before launch task":

From the "Add task" pop-up menu select "Run Gradle task":

In the Gradle tak window fill out the "Gradle project" and "Tasks" fields (they both have auto-complete):

Bear in mind: this advice might become obsolete as IntelliJ team changes their new UI.