The (archived) git-test tool from spotify allows you to run a command for a range of commits. I use it sometimes after rewriting my branch history before a merge to make sure every single commit still builds.
$ git test --verify 'mvn clean verify' origin/main...HEAD
Install with brew:
$ brew install git-test