You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+88-22
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,20 @@
3
3
4
4
# Git Code Format Maven Plugin
5
5
6
-
A maven plugin that automatically deploys [google-java-format](https://github.com/google/google-java-format)code formatter as a`pre-commit` git hook.
6
+
A maven plugin that automatically deploys code formatters as `pre-commit` git hook.
7
7
On commit, the hook will automatically format staged java files.
8
8
9
-
### Breaking changes between 2.x and 3.x
9
+
# Breaking changes between 3.x and 4.x
10
+
11
+
*`Google Java Format` is not enabled by default anymore. `com.cosium.code:google-java-format` must be added as a dependency to the plugin to keep using it.
12
+
*`Google Java Format` options declaration structure has changed. You will need to migrate any eventual existing declaration to the new structure described by [the google-java-format-options chapter](#google-java-format-options) .
13
+
14
+
# Breaking changes between 2.x and 3.x
10
15
11
16
*[#64](https://github.com/Cosium/git-code-format-maven-plugin/issues/64)`google-java-format 1.8`[dropped support for java 8](https://github.com/google/google-java-format/releases/tag/google-java-format-1.8).
12
17
The minimum supported runtime version for the plugin is JDK 11. i.e. Maven must run on JDK 11+ while the target project can still be built and run using JDK 8.
13
18
14
-
###Breaking changes between 1.x and 2.x
19
+
# Breaking changes between 1.x and 2.x
15
20
16
21
*[#37](https://github.com/Cosium/git-code-format-maven-plugin/issues/37) To prevent conflicts with other plugins all keys are now
17
22
prefixed with `gcf`. e.g. `-DglobPattern=**/*` becomes `-Dgcf.globPattern=**/*`
@@ -21,7 +26,7 @@ the plugin was renamed to `git-code-format-maven-plugin`. Its new coordinates ar
21
26
22
27
`1.x` documentation can be found [here](https://github.com/Cosium/git-code-format-maven-plugin/blob/1.39/README.md)
23
28
24
-
###Automatic code format and validation activation
29
+
# Automatic code format and validation activation
25
30
26
31
Add this to your maven project **root** pom.xml :
27
32
@@ -49,24 +54,34 @@ Add this to your maven project **root** pom.xml :
Thanks to its code formatter SPI, this plugin can execute any code formatter.
141
+
142
+
## How to
143
+
144
+
Note that you can take inspiration from the `google-java-format` module of this project.
145
+
146
+
1. Implement `com.cosium.code.format_spi.CodeFormatterFactory`. This interface is provided by `com.cosium.code:git-code-format-maven-plugin-spi`.
147
+
2. Add your `com.cosium.code.format_spi.CodeFormatterFactory` implementation canonical name in `META-INF/services/com.cosium.code.format_spi.CodeFormatterFactory`.
148
+
3. Pack this in a jar that you declare as a dependency in this plugin declaration.
149
+
150
+
## Example of usage
151
+
152
+
Suppose:
153
+
- the chosen `configurationId` (declared by `com.cosium.code.format_spi.CodeFormatterFactory#configurationId()`) is `aqme`
154
+
- the formatter dependency is `com.aqme.formatter:formatter:1.0`
155
+
156
+
A plugin declaration making use of this custom code formatter would look like this:
####If I have a multi-module project, do I need to install anything in the sub-projects?
188
+
## If I have a multi-module project, do I need to install anything in the sub-projects?
123
189
You only need to put the plugin in your *root* project pom.xml. By default all submodules will be handled.
124
190
125
-
####Do I need to run mvn initialize or is that a stage that happens automatically when I run mvn compile or mvn test?
191
+
## Do I need to run mvn initialize or is that a stage that happens automatically when I run mvn compile or mvn test?
126
192
`initialize` is the first phase of the Maven lifecycle. Any goal that you perform (e.g. `compile` or `test`) will automatically trigger `initialize` and thus trigger the git pre-commit hook installation.
127
193
128
-
####I'm not noticing anything happening.
194
+
## I'm not noticing anything happening.
129
195
If after setting up the plugin in your pom, you just executed a maven goal, the only expected output is a pre-commit hook installed in your `.git/hooks` directory. To trigger the automatic formatting, you have to perform a commit of a modified java file.
130
196
You can also manually [format](#manual-code-formatting) or [validate](#manual-code-format-validation) any file.
131
197
132
-
####I'd like to skip code formatting in a child project
198
+
## I'd like to skip code formatting in a child project
133
199
I inherit an enterprise parent pom, which I cannot modify, with formatting plugin specified, and I need to turn off formatting for my group's project.
134
200
Either use add a ```<skip>true</skip>``` configuration in the inheriting project or set the ```gcf.skip``` property to true.
135
201
136
-
###How the hook works
202
+
# How the hook works
137
203
138
204
On the `initialize` maven phase, `git-code-format:install-hooks` installs a git `pre-commit` hook that looks like this :
On `pre-commit` git phase, the hook triggers the `git-code-format:on-pre-commit` which formats the code of the modified java files using `google-java-format`.
216
+
On `pre-commit` git phase, the hook triggers the `git-code-format:on-pre-commit` which formats the code of the modified java files.
151
217
152
-
###Advanced pre-commit pipeline hook
218
+
# Advanced pre-commit pipeline hook
153
219
If you wish to modify the output of the pre-commit hook, you can set the `preCommitHookPipeline` configuration.
154
220
155
221
To completely ignore the hook output, you could use the following configuration:
0 commit comments