Formats your java code during the validate phase of your maven lifecycle
To skip the execution of the plugin, either put a <skip>true</skip>
tag in config or run your mvn install
command with -Dzg2pro.format.skip=true
zg2pro-formatter-plugin
requires Java 8+.
To install it in your project your project:
<plugin>
<groupId>com.github.zg2pro.formatter</groupId>
<artifactId>zg2pro-formatter-plugin</artifactId>
<version><!-- check the latest on http://central.maven.org/maven2/com/github/zg2pro/zg2pro-formatter-plugin/ --></version>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
This should be put only in the root pom.xml
At each execution, zg2pro-formatter-plugin goes through 1 preparation + 3 phases
The preparation only takes place when building the root project of your multi-modules project. It will still be run in a single module project. This preparation consists of writing a standardized .editorconfig file to your root directory, as well as writing a standardized .git/hooks/pre-commit file. If you want to use a different editorconfig or if you want to use your own pre-commit hooks, this plugin is not for you.
Then the first step, configures your git with the pre-commit script. This will check your code format everytime before you can commit your code with git. Each time, during this pre-commit, it will run the formatting. As the plugin formats the code by itself, if it finds unformatted code, you can restart your commit without any manual change.
The second step is the prettier java phase. Prettier uses prettier-java to format all your java code. This plugin bases on the indent-style set in the .editorconfig file. It will format .java files only.
Then, last but not least, editorconfig-java runs. It scans all the files which are not ignored by your .gitignore file, for each file selected, if this file is not binary data, it will run the editorconfig TextLinter and XmlLinter. Also it will check your files encoding.
When the plugin is inserted in your root pom.xml, you just run once a maven build (minimal phase= validate) and all will be setup.
You might want to override some of the rules from the .editorconfig file the plugin already downloads for you. In this case:
Either put a <allowModificationsOnEditorconfig>true</allowModificationsOnEditorconfig>
tag in config or run your mvn install
command with -Dzg2pro.format.allow.modifications.on.editorconfig=true
. When this is done add your file to your git sources.
If you don't use this option, we recommend you just ignore the .editorconfig file in your git repo and being generated by the plugin, it is no longer a source.
Another option is <applyEditorconfigOnlyWhenModified>true</applyEditorconfigOnlyWhenModified>
: This can help make things faster with big projects. The command line equivalent is -Dzg2pro.format.apply.editorconfig.only.when.modified=true
This library is developed under MIT License
Build and tests performed by travis CI
Major improvements are git-tagged and pushed to oss.sonatype/maven2 at the same time.