-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgetting-started.html
More file actions
511 lines (364 loc) · 20.7 KB
/
Copy pathgetting-started.html
File metadata and controls
511 lines (364 loc) · 20.7 KB
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 2.1.0 from src/site/xdoc/getting-started.xml.vm at 2026-08-30
| Rendered using Apache Maven Fluido Skin 2.0.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 2.1.0" />
<title>Get Started with Checkstyle – checkstyle</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-2.0.1.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script src="./js/apache-maven-fluido-2.0.1.min.js"></script>
<script type="text/javascript" src="./js/checkstyle.js" defer async></script>
<script type="text/javascript" src="./js/anchors.js" defer async></script>
<script type="text/javascript"
src="./js/google-analytics.js" defer async></script>
<script type="text/javascript"
src="./js/copy-clipboard.js" defer async></script>
<link rel="icon" href="./images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="./images/favicon.ico" type="image/ico" />
<script src="./js/search.js" defer async></script>
</head>
<body>
<div class="container-fluid container-fluid-top">
<header>
<div id="banner">
<div class="pull-left"><div id="bannerLeft"><h1><a href="./"><img class="class java.lang.Object" src="images/header-checkstyle-logo.png" alt="Checkstyle" /></a></h1></div></div>
<div class="pull-right"><div id="bannerRight"><h1><img class="class java.lang.Object" src="images/header-right-ruler.png" /></h1></div></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2026-08-30</li>
<li id="projectVersion" class="pull-right"><span class="divider">|</span>Version: 14.1.0</li>
<li class="pull-right"><a>toTop</a></li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span4">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">About</li>
<li><a href="index.html">Checkstyle</a></li>
<li><a href="release-notes.html">Release Notes</a></li>
<li><a href="consulting.html">Consulting</a></li>
<li><a href="sponsoring.html">Sponsoring</a></li>
<li class="nav-header">Documentation</li>
<li class="active"><a>Getting Started</a></li>
<li><a href="config.html"><span class="icon-chevron-down"></span>Configuration</a>
<ul class="nav nav-list">
<li><a href="property-types.html">Property Types</a></li>
<li><a href="config-system-properties.html">System Properties</a></li>
<li><a href="xpath.html">XPath</a></li>
</ul></li>
<li><a href="running.html"><span class="icon-chevron-down"></span>Running</a>
<ul class="nav nav-list">
<li><a href="ant-task.html">Ant Task</a></li>
<li><a href="cmdline.html">Command Line</a></li>
<li><a href="result-reports.html">Result Reports</a></li>
</ul></li>
<li><a href="checks.html"><span class="icon-chevron-down"></span>Checks</a>
<ul class="nav nav-list">
<li><a href="checks/annotation/index.html"><span class="icon-chevron-right"></span>Annotations</a></li>
<li><a href="checks/blocks/index.html"><span class="icon-chevron-right"></span>Block Checks</a></li>
<li><a href="checks/design/index.html"><span class="icon-chevron-right"></span>Class Design</a></li>
<li><a href="checks/coding/index.html"><span class="icon-chevron-right"></span>Coding</a></li>
<li><a href="checks/header/index.html"><span class="icon-chevron-right"></span>Headers</a></li>
<li><a href="checks/imports/index.html"><span class="icon-chevron-right"></span>Imports</a></li>
<li><a href="checks/javadoc/index.html"><span class="icon-chevron-right"></span>Javadoc Comments</a></li>
<li><a href="checks/metrics/index.html"><span class="icon-chevron-right"></span>Metrics</a></li>
<li><a href="checks/misc/index.html"><span class="icon-chevron-right"></span>Miscellaneous</a></li>
<li><a href="checks/modifier/index.html"><span class="icon-chevron-right"></span>Modifiers</a></li>
<li><a href="checks/modules/index.html"><span class="icon-chevron-right"></span>Modules</a></li>
<li><a href="checks/naming/index.html"><span class="icon-chevron-right"></span>Naming Conventions</a></li>
<li><a href="checks/regexp/index.html"><span class="icon-chevron-right"></span>Regexp</a></li>
<li><a href="checks/sizes/index.html"><span class="icon-chevron-right"></span>Size Violations</a></li>
<li><a href="checks/whitespace/index.html"><span class="icon-chevron-right"></span>Whitespace</a></li>
</ul></li>
<li><a href="filters/index.html"><span class="icon-chevron-right"></span>Filters</a></li>
<li><a href="filefilters/index.html"><span class="icon-chevron-right"></span>File Filters</a></li>
<li><a href="style-configs.html"><span class="icon-chevron-down"></span>Style Configurations</a>
<ul class="nav nav-list">
<li><a href="google-style.html">Google's Style</a></li>
<li><a href="openjdk-style.html">OpenJDK's Style</a></li>
<li><a href="sun-style.html">Sun's Style</a></li>
<li><a href="doc-comments-style.html">Documentation Comments Style</a></li>
</ul></li>
<li class="nav-header">Developers</li>
<li><a href="extending.html"><span class="icon-chevron-down"></span>Extending Checkstyle</a>
<ul class="nav nav-list">
<li><a href="writing-checks.html">Writing Checks</a></li>
<li><a href="writing-javadoc-checks.html">Writing Javadoc Checks</a></li>
<li><a href="writing-filters.html">Writing Filters</a></li>
<li><a href="writing-filefilters.html">Writing File Filters</a></li>
<li><a href="writing-listeners.html">Writing Listeners</a></li>
</ul></li>
<li><a href="contributing.html">Contributing</a></li>
<li><a href="beginning-development.html"><span class="icon-chevron-down"></span>Beginning Development</a>
<ul class="nav nav-list">
<li><a href="eclipse.html">Eclipse IDE</a></li>
<li><a href="netbeans.html">NetBeans IDE</a></li>
<li><a href="idea.html">IntelliJ IDE</a></li>
</ul></li>
<li><a href="apidocs/index.html">Javadoc</a></li>
<li class="nav-header">Project Documentation</li>
<li><a href="project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li>
<li><a href="project-reports.html"><span class="icon-chevron-right"></span>Project Reports</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<a href="https://github.com/checkstyle/checkstyle" class="builtBy"><img class="builtBy" src="images/github_logo_social_coding_outlined.png" alt="GitHub" /></a>
<a href="https://twitter.com/checkstyle_java/" class="builtBy"><img class="builtBy" src="images/twitter_button.png" alt="Twitter" /></a>
<a href="https://stackoverflow.com/questions/tagged/checkstyle" class="builtBy"><img class="builtBy" src="images/stackoverflow.jpeg" alt="Stackoverflow" /></a>
<a href="https://groups.google.com/forum/#!forum/checkstyle" class="builtBy"><img class="builtBy" src="images/groups.png" alt="GoogleGroups" /></a>
<a href="https://www.ej-technologies.com/products/jprofiler/overview.html" class="builtBy"><img class="builtBy" src="https://www.ej-technologies.com/images/product_banners/jprofiler_medium.png" alt="JProfiler" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span8">
<section><a id="Get_Started_with_Checkstyle"></a>
<h1>Get Started with Checkstyle</h1>
<div class="toc-panel">
<input type="checkbox" id="toc-toggle" class="toc-toggle-checkbox" checked="checked" />
<label for="toc-toggle" class="toc-toggle-arrow" title="Collapse"> </label>
<div class="toc-content">
<p class="toc-heading">On This Page</p>
<ul class="toc-list">
<li><a href="#Getting_Started_Add_a_starter_configuration"> 1. Add a starter configuration </a></li>
<li>
<input type="checkbox" id="toc-sub-Getting_Started_Run_Checkstyle" class="toc-sub-toggle-checkbox" checked="checked" />
<label for="toc-sub-Getting_Started_Run_Checkstyle" class="toc-sub-toggle">
<a href="#Getting_Started_Run_Checkstyle"> 2. Run Checkstyle </a><span class="toc-sub-arrow"></span> </label>
<ul class="toc-sublist">
<li><a href="#a2._Run_Checkstyle_Choose_how_you_want_to_run_Checkstyle" class="toc-sublink">Choose how you want to run Checkstyle</a></li>
<li><a href="#a2._Run_Checkstyle_Maven" class="toc-sublink">Maven</a></li>
<li><a href="#a2._Run_Checkstyle_Gradle" class="toc-sublink">Gradle</a></li>
<li><a href="#a2._Run_Checkstyle_Command_line" class="toc-sublink">Command line</a></li>
</ul>
</li>
<li><a href="#Getting_Started_Read_the_result"> 3. Read the result </a></li>
<li><a href="#Getting_Started_Choose_the_rules_for_your_project"> 4. Choose the rules for your project </a></li>
<li><a href="#Getting_Started_Where_to_go_next">Where to go next</a></li>
</ul>
</div>
</div>
<p>
Run Checkstyle on a Java project and see your first result in a few minutes. </p>
<p>
Checkstyle needs two things: <b>Java source code to analyze</b> and a <b>configuration that defines the checks to apply</b>. This guide starts with one simple check so you can verify that everything is working before choosing a complete coding standard. </p>
<p>
Before you begin, make sure your Java runtime is supported by the Checkstyle version you are using. See <a href="index.html#Additional_Information_JRE_and_JDK">JRE and JDK compatibility</a> for details. </p>
</section>
<a id="Getting_Started_Add_a_starter_configuration"></a><section id="Getting_Started_Add_a_starter_configuration"><a id="a1._Add_a_starter_configuration"></a>
<h1>1. Add a starter configuration</h1>
<p>
Every Checkstyle run uses a configuration file that defines which checks are enabled. </p>
<p>Create <code>config/checkstyle/checkstyle.xml</code>:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml"><?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="AvoidStarImport"/>
</module>
</module>
</code></pre></div>
<p>
This deliberately enables only <b>AvoidStarImport</b>, which reports wildcard imports such as: </p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">import java.util.*;</code></pre></div>
<p>
The configuration is intentionally small so that the first setup is easy to understand. It is <b>not intended to be a complete coding standard</b>. After Checkstyle is running, you can <a href="#a4._Choose_the_rules_for_your_project">adopt one of the supplied style configurations or add the checks your project needs</a>. </p>
</section>
<a id="Getting_Started_Run_Checkstyle"></a><section id="Getting_Started_Run_Checkstyle"><a id="a2._Run_Checkstyle"></a>
<h1>2. Run Checkstyle</h1>
<p>Choose one of the following methods. You only need to complete one.</p>
<a id="a2._Run_Checkstyle_Choose_how_you_want_to_run_Checkstyle"></a><section id="2._Run_Checkstyle_Choose_how_you_want_to_run_Checkstyle"><a id="Choose_how_you_want_to_run_Checkstyle"></a>
<h2>Choose how you want to run Checkstyle</h2>
<div class="cs-grid">
<a href="#a2._Run_Checkstyle_Maven" class="cs-card">
<p class="cs-card-title"><img src="images/logo-maven.svg" class="cs-card-logo" />Maven</p>
<p>Choose this if your project uses a <code>pom.xml</code>.</p>
</a> <a href="#a2._Run_Checkstyle_Gradle" class="cs-card">
<p class="cs-card-title"><img src="images/logo-gradle.svg" class="cs-card-logo" />Gradle</p>
<p>Choose this if your project uses <code>build.gradle</code> or <code>build.gradle.kts</code>.</p>
</a> <a href="#a2._Run_Checkstyle_Command_line" class="cs-card">
<p class="cs-card-title"><img src="images/logo-terminal.svg" class="cs-card-logo" />Command Line</p>
<p>Choose this if you want to try Checkstyle without changing your build.</p>
</a> </div>
<p>
Using Ant? See the <a href="ant-task.html">Checkstyle Ant Task</a> documentation. </p>
</section>
<a id="a2._Run_Checkstyle_Maven"></a><section id="2._Run_Checkstyle_Maven"><a id="Maven"></a>
<h2>Maven</h2>
<p>
Add the Maven Checkstyle Plugin to the <code><plugins></code> section of your <code>pom.xml</code>: </p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-xml"><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>14.1.0</version>
</dependency>
</dependencies>
</plugin></code></pre></div>
<p>Run:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-bash">./mvnw checkstyle:check</code></pre></div>
<p>
If your project does not use the Maven Wrapper, use <code>mvn checkstyle:check</code>. </p>
<p>
The Maven plugin has its own release cycle, so the Checkstyle dependency above is specified explicitly to use the version documented on this site. </p>
<p>
Once the setup works, you can configure Checkstyle to run automatically as part of your Maven build. See <a href="https://maven.apache.org/plugins/maven-checkstyle-plugin/" class="externalLink">Maven integration</a> for the available options. </p>
<p>
<a class="cs-btn cs-btn-secondary" href="#Getting_Started_Read_the_result">Next: Read the result →</a> </p>
</section>
<a id="a2._Run_Checkstyle_Gradle"></a><section id="2._Run_Checkstyle_Gradle"><a id="Gradle"></a>
<h2>Gradle</h2>
<p>
Apply Gradle's Checkstyle plugin and select the Checkstyle version to use. </p>
<p>For <code>build.gradle</code>:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-groovy">plugins {
id 'checkstyle'
}
checkstyle {
toolVersion = '14.1.0'
}</code></pre></div>
<p>For <code>build.gradle.kts</code>:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-kotlin">plugins {
checkstyle
}
checkstyle {
toolVersion = "14.1.0"
}</code></pre></div>
<p>
Gradle uses <code>config/checkstyle/checkstyle.xml</code> as the default Checkstyle configuration, so the starter configuration created above is already in the expected location. </p>
<p>Run Checkstyle against your main Java sources:</p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-bash">./gradlew checkstyleMain</code></pre></div>
<p>
If your project does not use the Gradle Wrapper, use <code>gradle checkstyleMain</code>. </p>
<p>
The Gradle <code>check</code> task also includes the Checkstyle tasks, so Checkstyle can become part of your normal project verification once you are ready. </p>
<p>
<a class="cs-btn cs-btn-secondary" href="#Getting_Started_Read_the_result">Next: Read the result →</a> </p>
</section>
<a id="a2._Run_Checkstyle_Command_line"></a><section id="2._Run_Checkstyle_Command_line"><a id="Command_line"></a>
<h2>Command line</h2>
<p>
The command line is the quickest way to try Checkstyle without modifying a Maven or Gradle build. </p>
<p>
Download <code>checkstyle-14.1.0-all.jar</code> from the <a href="https://github.com/checkstyle/checkstyle/releases/" class="externalLink">latest release</a>, then run: </p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-bash">java -jar checkstyle-14.1.0-all.jar \
-c config/checkstyle/checkstyle.xml \
src/main/java</code></pre></div>
<p>
Checkstyle accepts individual Java files or directories. When a directory is supplied, the files inside it are checked recursively. </p>
<p>
For all command-line options, see <a href="cmdline.html">Command Line</a>. </p>
<p>
<a class="cs-btn cs-btn-secondary" href="#Getting_Started_Read_the_result">Next: Read the result →</a> </p>
</section>
</section>
<a id="Getting_Started_Read_the_result"></a><section id="Getting_Started_Read_the_result"><a id="a3._Read_the_result"></a>
<h1>3. Read the result</h1>
<p>
If Checkstyle finds a wildcard import, you will see a diagnostic similar to: </p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-text">Starting audit...
[ERROR] Main.java:1:18: Using the '.*' form of import should be avoided. [AvoidStarImport]
Audit done.
Checkstyle ends with 1 errors.</code></pre></div>
<p>A Checkstyle diagnostic tells you:</p>
<ul>
<li>the file where the violation occurred;</li>
<li>the line and column;</li>
<li>what rule was violated;</li>
<li>and the Checkstyle check that reported it.</li>
</ul>
<p>
Here, <code>[AvoidStarImport]</code> tells you that the violation came from the <b>AvoidStarImport</b> check. Follow the check name to its documentation to learn what it checks and how it can be configured. </p>
<p>
If Checkstyle reports no violations, that is also a successful run — your code simply passes the configured rule. </p>
<p>
To verify the setup manually, temporarily add a wildcard import such as: </p>
<div class="wrapper">
<pre class="prettyprint"><code class="language-java">import java.util.*;</code></pre></div>
<p>
Run Checkstyle again and confirm that <code>AvoidStarImport</code> is reported. </p>
</section>
<a id="Getting_Started_Choose_the_rules_for_your_project"></a><section id="Getting_Started_Choose_the_rules_for_your_project"><a id="a4._Choose_the_rules_for_your_project"></a>
<h1>4. Choose the rules for your project</h1>
<p>
Now that Checkstyle is running, replace the starter configuration with the coding standard you actually want to enforce. </p>
<p>You can start from one of Checkstyle's supplied configurations:</p>
<div class="cs-grid">
<a href="google-style.html" class="cs-card">
<p class="cs-card-title"><img src="images/logo-google.svg" class="cs-card-logo" />Google Java Style</p>
<p>Start with Checkstyle's Google Java Style configuration.</p>
</a> <a href="sun-style.html" class="cs-card">
<p class="cs-card-title"><img src="images/logo-sun.svg" class="cs-card-logo" />Sun Conventions</p>
<p>Start with Checkstyle's Sun Conventions configuration.</p>
</a> <a href="openjdk-style.html" class="cs-card">
<p class="cs-card-title"><img src="images/logo-openjdk.svg" class="cs-card-logo" />OpenJDK Style</p>
<p>Start with Checkstyle's OpenJDK Style configuration.</p>
</a> <a href="doc-comments-style.html" class="cs-card">
<p class="cs-card-title"><img src="images/logo-doc.svg" class="cs-card-logo" />Doc Style</p>
<p>Start with Checkstyle's Doc Style configuration.</p>
</a> </div>
<p>
Or create your own configuration by choosing only the checks that make sense for your project. </p>
<p>
<a href="checks.html">Browse all checks →</a><br />
<a href="config.html">Learn how configuration works →</a> </p>
</section>
<a id="Getting_Started_Where_to_go_next"></a><section id="Getting_Started_Where_to_go_next"><a id="Where_to_go_next"></a>
<h1>Where to go next</h1>
<p>
You're ready. Checkstyle is now set up for your project. Explore the resources below when you want to customize rules, integrations, or advanced behavior. </p>
<ul>
<li><a href="checks.html">Browse Checks</a> to see the rules Checkstyle provides.</li>
<li><a href="config.html">Configuration</a> explains how to enable checks and change their properties.</li>
<li><a href="config_filters.html">Suppressions and Filters</a> let you handle intentional exceptions.</li>
<li><a href="running.html">Running Checkstyle</a> documents command-line and Ant execution in detail.</li>
<li>IDE integrations can provide faster feedback while you write code. See <a href="index.html#Related_Tools_Active_Tools">Active Tools</a>.</li>
<li>Maven and Gradle integrations can make Checkstyle part of your regular build and CI process.</li>
</ul>
<p>
For most projects, keep the Checkstyle configuration in version control so developers and automated builds use the same rules. </p>
</section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2001–2026
</p>
</div>
</div>
</footer>
</body>
</html>