The following instructions describe how to use the plugin in its simplest configuration. The following pom section will be able to get you started using the plugin.
<project ...> ... <plugins> <plugin> <groupId>net.revelc.code.formatter</groupId> <artifactId>formatter-maven-plugin</artifactId> <version>2.7.2</version> </plugin> </plugins> ... </project>
With this configuration, java source files in src/main/java and src/test/java of the project will be formatted using the default compiler version (1.5) and line ending of the current system.
Run the plugin with the format goal.
mvn formatter:format
In order to format the source files during the build, include the format goal in the plugin executions.
<project ...> ... <plugins> <plugin> <groupId>net.revelc.code.formatter</groupId> <artifactId>formatter-maven-plugin</artifactId> <version>2.7.2</version> <executions> <execution> <goals> <goal>format</goal> </goals> </execution> </executions> </plugin> </plugins> ... </project>
The source files will be formatted prior to compilation in the build lifecycle.
Run the plugin during the build with the compile goal.
mvn compile
mvn formatter:validate
In order to validate the source files during the build, include the validate goal in the plugin executions.
<project ...> ... <plugins> <plugin> <groupId>net.revelc.code.formatter</groupId> <artifactId>formatter-maven-plugin</artifactId> <version>2.7.2</version> <executions> <execution> <goals> <goal>validate</goal> </goals> </execution> </executions> </plugin> </plugins> ... </project>
If you want to override the default plugin behavior, check out custom configurations and how to configure it.