A Maven plugin for automated source code formatting using the Google Java Formatter, with configurable options.
This software is provided WITHOUT ANY WARRANTY, and is available under the Apache License, Version 2. Any code loss caused by using this plugin is not the responsibility of the author(s). Be sure to use some source repository management system such as GIT before using this plugin.
Contributions are welcome.
Add the plugin to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>io.github.mrdolch.formatter</groupId>
<artifactId>configurable-java-format-maven-plugin</artifactId>
<version>2025.21.1</version>
</plugin>
</plugins>
</build><repository>
<id>github</id>
<url>https://maven.pkg.github.com/MrDolch/configurable-java-format-maven-plugin</url>
</repository>Checks if the source code conforms to the formatting rules. The build will fail if the formatting is incorrect.
export MAVEN_OPTS="--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
mvn io.github.mrdolch.formatter:configurable-java-format-maven-plugin:checkFormats the source code according to the specified parameters.
export MAVEN_OPTS="--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
mvn io.github.mrdolch.formatter:configurable-java-format-maven-plugin:format| Parameter | Property | Default | Description |
|---|---|---|---|
aosp |
aosp |
false |
Use AOSP formatting style |
width |
width |
100 |
Maximum line length |
fixImportsOnly |
fixImportsOnly |
false |
Only fix imports |
skipSortingImports |
skipSortingImports |
false |
Do not sort imports |
skipRemovingUnusedImports |
skipRemovingUnusedImports |
false |
Do not remove unused imports |
skipReflowingLongStrings |
skipReflowingLongStrings |
false |
Do not reflow long strings |
skipJavadocFormatting |
skipJavadocFormatting |
false |
Do not format Javadoc comments |
<build>
<plugins>
<plugin>
<groupId>io.github.mrdolch.formatter</groupId>
<artifactId>configurable-format-maven-plugin</artifactId>
<version>2025.21.1</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
<configuration>
<width>120</width>
<fixImportsOnly>false</fixImportsOnly>
<skipSortingImports>false</skipSortingImports>
<skipRemovingUnusedImports>false</skipRemovingUnusedImports>
<skipReflowingLongStrings>false</skipReflowingLongStrings>
<skipJavadocFormatting>false</skipJavadocFormatting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>