I'm building a Pre-commit Git Hook script to apply code formatting with the help of Spring JavaFormat :
#!/bin/sh
./mvnw spring-javaformat:apply
When I commit an unformatted file, I notice the following:
- The command passes (after I verify my Git console).
- The target file is committed successfully without formatting changes.
- The formatting changes are applied but not committed.
I tried many ways to make it happen, but not one works, I'm wondering why and what is the way out for this?
This is how I added the plugin to my pom.xml file:
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<executions>
<execution>
<phase>validate</phase>
<inherited>true</inherited>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
System Requirements
- Maven v3.9.5 (with wrapper)
- Spring Boot v3.2
- Spring JavaFormat v0.0.40