IntelliJ - Run Gradle Task before Commit
IntelliJ has build in Support for
Before Commit Actions. E.g. Reformatting Code, optimize Imports and so on. But sometimes you want to execute a Gradle Task before Commit. We are using the Gradle Plugin Spotless to enforce consistent code formatting and style, ensuring readability and maintainability across the codebase.
But we struggle to manually run the Gradle Task before each commit.
We gladly found a way to Run the Gradle Task before each commit using the
IntelliJ - Before Commit - Run Configuration, where you can select a Gradle Task which is executed before each commit.
I'm not quit sure, why only Gradle Tasks are supported. I was hoping to run e.g. npm tasks as well, but I was not able to select the Run Configurations for other Tasks then Gradle
So before your commit, the task gets executed:
I hope this saves a few CI Minutes due to failed builds due to e.g. Spotless