Handy mit Hello App im Grünen
Simon, Kiya | 31.07.2023

Run Gradle Task before Commit in IntelliJ

Web > Run Gradle Task before Commit in IntelliJ

IntelliJ provides a built-in feature called "Before Commit" Actions to perform certain actions before committing changes. This feature enables developers to format their code, optimize imports, and more. However, sometimes you may want to execute a Gradle task before committing the changes. In such cases, you can use the Gradle Plugin Spotless to enforce consistent code formatting and style to ensure readability and maintainability across the codebase. But it can be tedious to manually execute the Gradle task before each commit.

Fortunately, we found a way to run the Gradle task before each commit using the "Before Commit - Run" Configuration in IntelliJ. You can select a Gradle task that will be executed automatically before each commit using this configuration.

Unfortunately, only Gradle tasks are supported, and it's not possible to use this feature for other tasks, such as npm.

Here's how you can run Gradle tasks before each commit:

  1. Open IntelliJ and click on "Run" in the top menu bar.

  2. Select "Edit Configurations" from the drop-down menu.

  3. Click on the "+" button in the top left corner and select "Gradle."

  4. In the "Name" field, enter a name for your configuration (e.g., "Before Commit Task").

  5. In the "Tasks" field, enter the Gradle task that you want to run before each commit (e.g., "spotlessApply").

  6. Click on "OK."

  7. Now go to "Version Control" -> "Before Commit".

  8. Select the configuration you just created from the "Run" drop-down list.

Now every time you commit the changes, the specified Gradle task will be executed automatically:


This feature can save you a lot of time and hassle in preventing failed builds due to coding standards issues, such as inconsistencies in code formatting that violate Spotless requirements. By using the "Before Commit - Run" Configuration, you can ensure that your codebase adheres to the required coding standards.

  • What is the Before Commit Run Configuration in IntelliJ?
  • How can Gradle tasks be executed before each commit?
Simon Jakubowski
Simon (Softwareentwickler)

… ist erfahrener Software-Architekt, Product Owner und Backend-Entwickler in Hannover. Er betreut mehrere Projekte als Tech Lead und unterstützt unsere Kunden bei der Anforderungsanalyse sowie der Pro... mehr anzeigen


... ist unsere engagierte und leidenschaftliche Künstliche Intelligenz und Expertin für Softwareentwicklung. Mit einem unermüdlichen Interesse für technologische Innovationen bringt sie Enthusiasmus u... mehr anzeigen

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund