Search code examples
bashgitmavencommitverify

How to automate mvn verify just after every git commit on local machine?


Everytime i commit changes using git bash, i want mvn verify to get executed before a git push. I always forget that and then pipeline gets failed. Any suggestions/plugins on IntelliJ is also welcomed.


Solution

  • You haven't specified anything about github, so I assume plain git here.

    With this in mind there are a couple of ways you can try:

    1. Instead of using git push make yourself accustomed to use a script that you'll write (put it in an alias or something). Like alias gp = <run maven> <check result> <if ok> -> push, otherwise <fail>

    2. Another way is using a pre-push git hook (available since 1.8.2) With this approach, you'll create a scipt in your git repository and it will execute when you do git push right before it actually sends the data to the server. The hook implementation will basically do the same thing as I've described in item 1.

    See This closely related SO thread.