/
usage.apt.vm
270 lines (239 loc) · 7.34 KB
/
usage.apt.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
------
Introduction
------
John Freeman
------
2018-05-10
------
~~ #%L
~~ ktlint-maven-plugin
~~ %%
~~ Copyright (C) 2018 GantSign Ltd.
~~ %%
~~ Permission is hereby granted, free of charge, to any person obtaining a copy
~~ of this software and associated documentation files (the "Software"), to deal
~~ in the Software without restriction, including without limitation the rights
~~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~~ copies of the Software, and to permit persons to whom the Software is
~~ furnished to do so, subject to the following conditions:
~~
~~ The above copyright notice and this permission notice shall be included in
~~ all copies or substantial portions of the Software.
~~
~~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~~ THE SOFTWARE.
~~ #L%
Usage
Some brief examples on how to use this plugin.
* Using Java 17 and later
Java 17 is the first LTS release to enforce strong encapsulation. For
<<<ktlint>>> to work we need to add
<<<--add-opens java.base/java.lang=ALL-UNNAMED>>> to the JVM arguments.
We recommend that you add a <<<.mvn/jvm.config>>> file (relative to the top
level project directory) to all of your projects using this plugin. The file
should have the following contents:
+----------+
--add-opens java.base/java.lang=ALL-UNNAMED
+----------+
We also recommend adding this to all of your projects using this plugin and
building with Java 11, as it'll suppress an illegal-access warning during the
build.
For other options see: {{https://maven.apache.org/configure.html}}
* Formatting and checking for violations as part of the build
Probably the most common use case is to want to both format and check your
code; add the following plugin configuration to your POM.
+----------+
<build>
<plugins>
...
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>format-and-check</id>
<goals>
<goal>format</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
+----------+
* Formatting as part of the build
If you just want ktlint to automatically fix what it can, add the following
plugin configuration to your POM.
+----------+
<build>
<plugins>
...
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>format</id>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
+----------+
To run this from the command line (without adding the plugin to your POM) you
can run the following from your console:
+----------+
mvn ${project.groupId}:${project.artifactId}:${project.version}:format
+----------+
* Checking for violations as part of the build
If you just want to drill good habits into your developers, add the following
plugin configuration to your POM.
+----------+
<build>
<plugins>
...
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
+----------+
To run this from the command line (without adding the plugin to your POM) you
can run the following from your console:
+----------+
mvn ${project.groupId}:${project.artifactId}:${project.version}:check
+----------+
* Generate ktlint report as part of the project reports
To generate the ktlint report as part of the project reports, add the ktlint
plugin in the <<<\<reporting\>>>> section of your POM.
+----------+
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<!-- ktlint-maven plugin requires maven-site-plugin >= 3.7.0 to work -->
<version>3.7.1</version>
</plugin>
...
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
...
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${project.version}</version>
</plugin>
...
</plugins>
</reporting>
+----------+
* Using ktlint reporters as part of the build
As well as Maven project reports that are part of the Maven site (see above)
this plugin also supports ktlint reporters:
+----------+
<build>
<plugins>
...
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>reporter</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<failOnViolation>false</failOnViolation>
<reporters>
<reporter>
<name>plain</name>
<output>\${project.build.directory}/ktlint.txt</output>
<properties>
<property>
<name>group_by_file</name>
<value>true</value>
</property>
</properties>
</reporter>
</reporters>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
+----------+
The built in reporters are <<<plain>>>, <<<json>>> and <<<checkstyle>>>. You
can also provide a customer reporter (see
{{https://github.com/pinterest/ktlint}} for details); to use a custom reporter
it needs to be added as a Maven dependency to the Maven plugin e.g.:
+----------+
<build>
<plugins>
...
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<failOnViolation>false</failOnViolation>
<reporters>
<reporter>
<name>my-custom-reporter</name>
<output>\${project.build.directory}/ktlint.rpt</output>
</reporter>
</reporters>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>my-custom-reporter</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
</build>
+----------+