Cosium / git-code-format-maven-plugin

A maven plugin that automatically deploys code formatters as pre-commit git hook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pre-commit hook on aggregate project runs for each module

chonton opened this issue · comments

I have a multi-module project with five child modules. When the pre-commit hook runs, there are five invocations of the on-pre-commit goal.

$ mvn git-code-format:on-pre-commit
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] java-base                                                          [pom]
[INFO] client-lib                                                         [jar]
[INFO] test-lib                                                           [jar]
[INFO] service-lib                                                        [jar]
[INFO] archetype                                              [maven-archetype]
[INFO] 
[INFO] ----------------< org.honton.chas:java-base >----------------
[INFO] Building java-base 1.27.0-SNAPSHOT                                 [1/5]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-git-code-format:1.39:on-pre-commit (default-cli) @ java-base ---
[INFO] Executing pre-commit hooks
[INFO] Formatting 'service-lib/src/main/java/org/honton/chas/jaxrs/container/AuthnContainerRequestFilter.java'
[INFO] Formatted 'service-lib/src/main/java/org/honton/chas/jaxrs/container/AuthnContainerRequestFilter.java'
[INFO] Executed pre-commit hooks
[INFO] 
[INFO] ---------------< org.honton.chas:client-lib >----------------
[INFO] Building client-lib 1.27.0-SNAPSHOT                                [2/5]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-git-code-format:1.39:on-pre-commit (default-cli) @ client-lib ---
[INFO] Executing pre-commit hooks
[INFO] Executed pre-commit hooks
[INFO] 
[INFO] ----------------< org.honton.chas:test-lib >-----------------
[INFO] Building test-lib 1.27.0-SNAPSHOT                                  [3/5]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-git-code-format:1.39:on-pre-commit (default-cli) @ test-lib ---
[INFO] Executing pre-commit hooks
[INFO] Executed pre-commit hooks
[INFO] 
[INFO] ---------------< org.honton.chas:service-lib >---------------
[INFO] Building service-lib 1.27.0-SNAPSHOT                               [4/5]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-git-code-format:1.39:on-pre-commit (default-cli) @ service-lib ---
[INFO] Executing pre-commit hooks
[INFO] Formatting 'service-lib/src/main/java/org/honton/chas/jaxrs/container/AuthnContainerRequestFilter.java'
[INFO] Formatted 'service-lib/src/main/java/org/honton/chas/jaxrs/container/AuthnContainerRequestFilter.java'
[INFO] Executed pre-commit hooks
[INFO] 
[INFO] --------------------< org.honton.chas:archetype >--------------------
[INFO] Building archetype 1.27.0-SNAPSHOT                                 [5/5]
[INFO] --------------------------[ maven-archetype ]---------------------------
[INFO] 
[INFO] --- maven-git-code-format:1.39:on-pre-commit (default-cli) @ archetype ---
[INFO] Executing pre-commit hooks
[INFO] Executed pre-commit hooks
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for java-base 1.27.0-SNAPSHOT:
[INFO] 
[INFO] java-base .......................................... SUCCESS [  1.248 s]
[INFO] client-lib ......................................... SUCCESS [  0.078 s]
[INFO] test-lib ........................................... SUCCESS [  0.066 s]
[INFO] service-lib ........................................ SUCCESS [  0.118 s]
[INFO] archetype .......................................... SUCCESS [  0.441 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.370 s
[INFO] Finished at: 2020-02-27T11:37:34-08:00
[INFO] ------------------------------------------------------------------------

Is this the expected behavior? Should the plugin goal only be run at the top level? If so, the '-N' parameter can be used.

$ mvn -N git-code-format:on-pre-commit
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< org.honton.chas:java-base >----------------
[INFO] Building java-base 1.27.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-git-code-format:1.39:on-pre-commit (default-cli) @ java-base ---
[INFO] Executing pre-commit hooks
[INFO] Formatting 'service-lib/src/main/java/org/honton/chas/jaxrs/container/AuthnContainerRequestFilter.java'
[INFO] Formatted 'service-lib/src/main/java/org/honton/chas/jaxrs/container/AuthnContainerRequestFilter.java'
[INFO] Executed pre-commit hooks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.065 s
[INFO] Finished at: 2020-02-27T11:43:04-08:00
[INFO] ------------------------------------------------------------------------

It works as expected.
This allows to format each module src/main/java directory.
It also allows to easily exclude a module from the pre commit hook process.

If you think there is a better way to do it while keeping the current list of features, please contribute.