PageSourceSearch

https://checkstyle.org/getting-started.html

html checkstyle.org collected 2026-09-24 17:34:44 UTC 21,155 bytes, 511 lines download raw bytes

1<!DOCTYPE html>
2
3
4<!--
5 | Generated by Apache Maven Doxia Site Renderer 2.1.0 from src/site/xdoc/getting-started.xml.vm at 2026-08-30
6 | Rendered using Apache Maven Fluido Skin 2.0.1
7-->
8<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
9  <head>
10    <meta charset="UTF-8" />
11    <meta name="viewport" content="width=device-width, initial-scale=1" />
12    <meta name="generator" content="Apache Maven Doxia Site Renderer 2.1.0" />
13    <title>Get Started with Checkstyle – checkstyle</title>
14    <link rel="stylesheet" href="./css/apache-maven-fluido-2.0.1.min.css" />
15    <link rel="stylesheet" href="./css/site.css" />
16    <link rel="stylesheet" href="./css/print.css" media="print" />
17    
17<script src="./js/apache-maven-fluido-2.0.1.min.js"></script>
vendor: 1 bytes, line 17
17
18<script type="text/javascript" src="./js/checkstyle.js" defer async></script>
18
19        
19<script type="text/javascript" src="./js/anchors.js" defer async></script>
19
20        
20<script type="text/javascript"
21                src="./js/google-analytics.js" defer async></script>
21
22        
22<script type="text/javascript"
23                src="./js/copy-clipboard.js" defer async></script>
23
24        <link rel="icon" href="./images/favicon.png" type="image/x-icon" />
25        <link rel="shortcut icon" href="./images/favicon.ico" type="image/ico" />
26        
26<script src="./js/search.js" defer async></script>
26
27  </head>
28  <body>
29    <div class="container-fluid container-fluid-top">
30      <header>
31        <div id="banner">
32          <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>
33          <div class="pull-right"><div id="bannerRight"><h1><img class="class java.lang.Object" src="images/header-right-ruler.png" /></h1></div></div>
34          <div class="clear"><hr/></div>
35        </div>
36
37        <div id="breadcrumbs">
38          <ul class="breadcrumb">
39        <li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2026-08-30</li>
40          <li id="projectVersion" class="pull-right"><span class="divider">|</span>Version: 14.1.0</li>
41        <li class="pull-right"><a>toTop</a></li>
42          </ul>
43        </div>
44      </header>
45      <div class="row-fluid">
46        <header id="leftColumn" class="span4">
47          <nav class="well sidebar-nav">
48  <ul class="nav nav-list">
49   <li class="nav-header">About</li>
50    <li><a href="index.html">Checkstyle</a></li>
51    <li><a href="release-notes.html">Release Notes</a></li>
52    <li><a href="consulting.html">Consulting</a></li>
53    <li><a href="sponsoring.html">Sponsoring</a></li>
54   <li class="nav-header">Documentation</li>
55    <li class="active"><a>Getting Started</a></li>
56    <li><a href="config.html"><span class="icon-chevron-down"></span>Configuration</a>
57     <ul class="nav nav-list">
58      <li><a href="property-types.html">Property Types</a></li>
59      <li><a href="config-system-properties.html">System Properties</a></li>
60      <li><a href="xpath.html">XPath</a></li>
61     </ul></li>
62    <li><a href="running.html"><span class="icon-chevron-down"></span>Running</a>
63     <ul class="nav nav-list">
64      <li><a href="ant-task.html">Ant Task</a></li>
65      <li><a href="cmdline.html">Command Line</a></li>
66      <li><a href="result-reports.html">Result Reports</a></li>
67     </ul></li>
68    <li><a href="checks.html"><span class="icon-chevron-down"></span>Checks</a>
69     <ul class="nav nav-list">
70      <li><a href="checks/annotation/index.html"><span class="icon-chevron-right"></span>Annotations</a></li>
71      <li><a href="checks/blocks/index.html"><span class="icon-chevron-right"></span>Block Checks</a></li>
72      <li><a href="checks/design/index.html"><span class="icon-chevron-right"></span>Class Design</a></li>
73      <li><a href="checks/coding/index.html"><span class="icon-chevron-right"></span>Coding</a></li>
74      <li><a href="checks/header/index.html"><span class="icon-chevron-right"></span>Headers</a></li>
75      <li><a href="checks/imports/index.html"><span class="icon-chevron-right"></span>Imports</a></li>
76      <li><a href="checks/javadoc/index.html"><span class="icon-chevron-right"></span>Javadoc Comments</a></li>
77      <li><a href="checks/metrics/index.html"><span class="icon-chevron-right"></span>Metrics</a></li>
78      <li><a href="checks/misc/index.html"><span class="icon-chevron-right"></span>Miscellaneous</a></li>
79      <li><a href="checks/modifier/index.html"><span class="icon-chevron-right"></span>Modifiers</a></li>
80      <li><a href="checks/modules/index.html"><span class="icon-chevron-right"></span>Modules</a></li>
81      <li><a href="checks/naming/index.html"><span class="icon-chevron-right"></span>Naming Conventions</a></li>
82      <li><a href="checks/regexp/index.html"><span class="icon-chevron-right"></span>Regexp</a></li>
83      <li><a href="checks/sizes/index.html"><span class="icon-chevron-right"></span>Size Violations</a></li>
84      <li><a href="checks/whitespace/index.html"><span class="icon-chevron-right"></span>Whitespace</a></li>
85     </ul></li>
86    <li><a href="filters/index.html"><span class="icon-chevron-right"></span>Filters</a></li>
87    <li><a href="filefilters/index.html"><span class="icon-chevron-right"></span>File Filters</a></li>
88    <li><a href="style-configs.html"><span class="icon-chevron-down"></span>Style Configurations</a>
89     <ul class="nav nav-list">
90      <li><a href="google-style.html">Google&apos;s Style</a></li>
91      <li><a href="openjdk-style.html">OpenJDK&apos;s Style</a></li>
92      <li><a href="sun-style.html">Sun&apos;s Style</a></li>
93      <li><a href="doc-comments-style.html">Documentation Comments Style</a></li>
94     </ul></li>
95   <li class="nav-header">Developers</li>
96    <li><a href="extending.html"><span class="icon-chevron-down"></span>Extending Checkstyle</a>
97     <ul class="nav nav-list">
98      <li><a href="writing-checks.html">Writing Checks</a></li>
99      <li><a href="writing-javadoc-checks.html">Writing Javadoc Checks</a></li>
100      <li><a href="writing-filters.html">Writing Filters</a></li>
101      <li><a href="writing-filefilters.html">Writing File Filters</a></li>
102      <li><a href="writing-listeners.html">Writing Listeners</a></li>
103     </ul></li>
104    <li><a href="contributing.html">Contributing</a></li>
105    <li><a href="beginning-development.html"><span class="icon-chevron-down"></span>Beginning Development</a>
106     <ul class="nav nav-list">
107      <li><a href="eclipse.html">Eclipse IDE</a></li>
108      <li><a href="netbeans.html">NetBeans IDE</a></li>
109      <li><a href="idea.html">IntelliJ IDE</a></li>
110     </ul></li>
111    <li><a href="apidocs/index.html">Javadoc</a></li>
112   <li class="nav-header">Project Documentation</li>
113    <li><a href="project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li>
114    <li><a href="project-reports.html"><span class="icon-chevron-right"></span>Project Reports</a></li>
115  </ul>
116          </nav>
117          <div class="well sidebar-nav">
118            <div id="poweredBy">
119              <div class="clear"></div>
120              <div class="clear"></div>
121<a href="https://github.com/checkstyle/checkstyle" class="builtBy"><img class="builtBy" src="images/github_logo_social_coding_outlined.png" alt="GitHub" /></a>
122<a href="https://twitter.com/checkstyle_java/" class="builtBy"><img class="builtBy" src="images/twitter_button.png" alt="Twitter" /></a>
123<a href="https://stackoverflow.com/questions/tagged/checkstyle" class="builtBy"><img class="builtBy" src="images/stackoverflow.jpeg" alt="Stackoverflow" /></a>
124<a href="https://groups.google.com/forum/#!forum/checkstyle" class="builtBy"><img class="builtBy" src="images/groups.png" alt="GoogleGroups" /></a>
125<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>
126            </div>
127          </div>
128        </header>
129        <main id="bodyColumn" class="span8">
130
131
132
133
134<section><a id="Get_Started_with_Checkstyle"></a>
135<h1>Get Started with Checkstyle</h1>
136
137<div class="toc-panel">
138<input type="checkbox" id="toc-toggle" class="toc-toggle-checkbox" checked="checked" />
139<label for="toc-toggle" class="toc-toggle-arrow" title="Collapse">&#160;</label>
140
141<div class="toc-content">
142
143<p class="toc-heading">On This Page</p>
144
145<ul class="toc-list">
146
147<li><a href="#Getting_Started_Add_a_starter_configuration"> 1. Add a starter configuration </a></li>
148
149<li>
150<input type="checkbox" id="toc-sub-Getting_Started_Run_Checkstyle" class="toc-sub-toggle-checkbox" checked="checked" />
151<label for="toc-sub-Getting_Started_Run_Checkstyle" class="toc-sub-toggle">
152<a href="#Getting_Started_Run_Checkstyle"> 2. Run Checkstyle </a><span class="toc-sub-arrow"></span> </label>
153
154<ul class="toc-sublist">
155
156<li>
156<a href="#a2._Run_Checkstyle_Choose_how_you_want_to_run_Checkstyle" class="toc-sublink">Choose how you want to run Checkstyle</a></li>
157
158<li><a href="#a2._Run_Checkstyle_Maven" class="toc-sublink">Maven</a></li>
159
160<li><a href="#a2._Run_Checkstyle_Gradle" class="toc-sublink">Gradle</a></li>
161
162<li><a href="#a2._Run_Checkstyle_Command_line" class="toc-sublink">Command line</a></li>
163</ul>
164</li>
165
166<li><a href="#Getting_Started_Read_the_result"> 3. Read the result </a></li>
167
168<li><a href="#Getting_Started_Choose_the_rules_for_your_project"> 4. Choose the rules for your project </a></li>
169
170<li><a href="#Getting_Started_Where_to_go_next">Where to go next</a></li>
171</ul>
172</div>
173</div>
174
175<p>
176Run Checkstyle on a Java project and see your first result in a few minutes. </p>
177
178
179<p>
180Checkstyle 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>
181
182
183<p>
184Before 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>
185</section>
186
187<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>
188<h1>1. Add a starter configuration</h1>
189
190<p>
191Every Checkstyle run uses a configuration file that defines which checks are enabled. </p>
192
193
194<p>Create <code>config/checkstyle/checkstyle.xml</code>:</p>
195
196
197<div class="wrapper">
198<pre class="prettyprint"><code class="language-xml">&lt;?xml version=&quot;1.0&quot;?&gt;
199&lt;!DOCTYPE module PUBLIC
200  &quot;-//Checkstyle//DTD Checkstyle Configuration 1.3//EN&quot;
201  &quot;https://checkstyle.org/dtds/configuration_1_3.dtd&quot;&gt;
202
203&lt;module name=&quot;Checker&quot;&gt;
204  &lt;module name=&quot;TreeWalker&quot;&gt;
205    &lt;module name=&quot;AvoidStarImport&quot;/&gt;
206  &lt;/module&gt;
207&lt;/module&gt;
208</code></pre></div>
209
210
211<p>
212This deliberately enables only <b>AvoidStarImport</b>, which reports wildcard imports such as: </p>
213
214
215<div class="wrapper">
216<pre class="prettyprint"><code class="language-java">import java.util.*;</code></pre></div>
217
218
219<p>
220The 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>
221</section>
222
223<a id="Getting_Started_Run_Checkstyle"></a><section id="Getting_Started_Run_Checkstyle"><a id="a2._Run_Checkstyle"></a>
224<h1>2. Run Checkstyle</h1>
225
226<p>Choose one of the following methods. You only need to complete one.</p>
227
228<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>
229<h2>Choose how you want to run Checkstyle</h2>
230
231<div class="cs-grid">
232<a href="#a2._Run_Checkstyle_Maven" class="cs-card"> 
233<p class="cs-card-title"><img src="images/logo-maven.svg" class="cs-card-logo" />Maven</p>
234
235<p>Choose this if your project uses a <code>pom.xml</code>.</p>
236</a> <a href="#a2._Run_Checkstyle_Gradle" class="cs-card"> 
237<p class="cs-card-title"><img src="images/logo-gradle.svg" class="cs-card-logo" />Gradle</p>
238
239<p>Choose this if your project uses <code>build.gradle</code> or <code>build.gradle.kts</code>.</p>
240</a> <a href="#a2._Run_Checkstyle_Command_line" class="cs-card"> 
241<p class="cs-card-title"><img src="images/logo-terminal.svg" class="cs-card-logo" />Command Line</p>
242
243<p>Choose this if you want to try Checkstyle without changing your build.</p>
244</a> </div>
245
246<p>
247Using Ant? See the <a href="ant-task.html">Checkstyle Ant Task</a> documentation. </p>
248</section>
249
250<a id="a2._Run_Checkstyle_Maven"></a><section id="2._Run_Checkstyle_Maven"><a id="Maven"></a>
251<h2>Maven</h2>
252
253<p>
254Add the Maven Checkstyle Plugin to the <code>&lt;plugins&gt;</code> section of your <code>pom.xml</code>: </p>
255
256
257<div class="wrapper">
258<pre class="prettyprint"><code class="language-xml">&lt;plugin&gt;
259  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
260  &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
261  &lt;version&gt;3.6.0&lt;/version&gt;
262
263  &lt;configuration&gt;
264    &lt;configLocation&gt;config/checkstyle/checkstyle.xml&lt;/configLocation&gt;
265  &lt;/configuration&gt;
266
267  &lt;dependencies&gt;
268    &lt;dependency&gt;
269      &lt;groupId&gt;com.puppycrawl.tools&lt;/groupId&gt;
270      &lt;artifactId&gt;checkstyle&lt;/artifactId&gt;
271      &lt;version&gt;14.1.0&lt;/version&gt;
272    &lt;/dependency&gt;
273  &lt;/dependencies&gt;
274&lt;/plugin&gt;</code></pre></div>
275
276
277<p>Run:</p>
278
279
280<div class="wrapper">
281<pre class="prettyprint"><code class="language-bash">./mvnw checkstyle:check</code></pre></div>
282
283
284<p>
285If your project does not use the Maven Wrapper, use <code>mvn checkstyle:check</code>. </p>
286
287
288<p>
289The Maven plugin has its own release cycle, so the Checkstyle dependency above is specified explicitly to use the version documented on this site. </p>
290
291
292<p>
293Once 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>
294
295<p>
296<a class="cs-btn cs-btn-secondary" href="#Getting_Started_Read_the_result">Next: Read the result &#x2192;</a> </p>
297</section>
298
299<a id="a2._Run_Checkstyle_Gradle"></a><section id="2._Run_Checkstyle_Gradle"><a id="Gradle"></a>
300<h2>Gradle</h2>
301
302<p>
303Apply Gradle's Checkstyle plugin and select the Checkstyle version to use. </p>
304
305
306<p>For <code>build.gradle</code>:</p>
307
308
309<div class="wrapper">
310<pre class="prettyprint"><code class="language-groovy">plugins {
311  id 'checkstyle'
312}
313
314checkstyle {
315  toolVersion = '14.1.0'
316}</code></pre></div>
317
318
319<p>For <code>build.gradle.kts</code>:</p>
320
321
322<div class="wrapper">
323<pre class="prettyprint"><code class="language-kotlin">plugins {
324  checkstyle
325}
326
327checkstyle {
328  toolVersion = &quot;14.1.0&quot;
329}</code></pre></div>
330
331
332<p>
333Gradle 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>
334
335
336<p>Run Checkstyle against your main Java sources:</p>
337
338
339<div class="wrapper">
340<pre class="prettyprint"><code class="language-bash">./gradlew checkstyleMain</code></pre></div>
341
342
343<p>
344If your project does not use the Gradle Wrapper, use <code>gradle checkstyleMain</code>. </p>
345
346
347<p>
348The 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>
349
350<p>
351<a class="cs-btn cs-btn-secondary" href="#Getting_Started_Read_the_result">Next: Read the result &#x2192;</a> </p>
352</section>
353
354<a id="a2._Run_Checkstyle_Command_line"></a><section id="2._Run_Checkstyle_Command_line"><a id="Command_line"></a>
355<h2>Command line</h2>
356
357<p>
358The command line is the quickest way to try Checkstyle without modifying a Maven or Gradle build. </p>
359
360
361<p>
362Download <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>
363
364
365<div class="wrapper">
366<pre class="prettyprint"><code class="language-bash">java -jar checkstyle-14.1.0-all.jar \
367  -c config/checkstyle/checkstyle.xml \
368  src/main/java</code></pre></div>
369
370
371<p>
372Checkstyle accepts individual Java files or directories. When a directory is supplied, the files inside it are checked recursively. </p>
373
374
375<p>
376For all command-line options, see <a href="cmdline.html">Command Line</a>. </p>
377
378<p>
379<a class="cs-btn cs-btn-secondary" href="#Getting_Started_Read_the_result">Next: Read the result &#x2192;</a> </p>
380</section>
381</section>
382
383<a id="Getting_Started_Read_the_result"></a><section id="Getting_Started_Read_the_result"><a id="a3._Read_the_result"></a>
384<h1>3. Read the result</h1>
385
386<p>
387If Checkstyle finds a wildcard import, you will see a diagnostic similar to: </p>
388
389
390<div class="wrapper">
391<pre class="prettyprint"><code class="language-text">Starting audit...
392[ERROR] Main.java:1:18: Using the '.*' form of import should be avoided. [AvoidStarImport]
393Audit done.
394Checkstyle ends with 1 errors.</code></pre></div>
395
396
397<p>A Checkstyle diagnostic tells you:</p>
398
399<ul>
400
401<li>the file where the violation occurred;</li>
402
403<li>the line and column;</li>
404
405<li>what rule was violated;</li>
406
407<li>and the Checkstyle check that reported it.</li>
408</ul>
409
410
411<p>
412Here, <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>
413
414
415<p>
416If Checkstyle reports no violations, that is also a successful run &#x2014; your code simply passes the configured rule. </p>
417
418
419<p>
420To verify the setup manually, temporarily add a wildcard import such as: </p>
421
422
423<div class="wrapper">
424<pre class="prettyprint"><code class="language-java">import java.util.*;</code></pre></div>
425
426
427<p>
428Run Checkstyle again and confirm that <code>AvoidStarImport</code> is reported. </p>
429</section>
430
431<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>
432<h1>4. Choose the rules for your project</h1>
433
434<p>
435Now that Checkstyle is running, replace the starter configuration with the coding standard you actually want to enforce. </p>
436
437
438<p>You can start from one of Checkstyle's supplied configurations:</p>
439
440
441<div class="cs-grid">
442<a href="google-style.html" class="cs-card"> 
443<p class="cs-card-title"><img src="images/logo-google.svg" class="cs-card-logo" />Google Java Style</p>
444
445<p>Start with Checkstyle's Google Java Style configuration.</p>
446</a> <a href="sun-style.html" class="cs-card"> 
447<p class="cs-card-title"><img src="images/logo-sun.svg" class="cs-card-logo" />Sun Conventions</p>
448
449<p>Start with Checkstyle's Sun Conventions configuration.</p>
450</a> <a href="openjdk-style.html" class="cs-card"> 
451<p class="cs-card-title"><img src="images/logo-openjdk.svg" class="cs-card-logo" />OpenJDK Style</p>
452
453<p>Start with Checkstyle's OpenJDK Style configuration.</p>
454</a> <a href="doc-comments-style.html" class="cs-card"> 
455<p class="cs-card-title"><img src="images/logo-doc.svg" class="cs-card-logo" />Doc Style</p>
456
457<p>Start with Checkstyle's Doc Style configuration.</p>
458</a> </div>
459
460
461<p>
462Or create your own configuration by choosing only the checks that make sense for your project. </p>
463
464
465<p>
466<a href="checks.html">Browse all checks &#x2192;</a><br />
467<a href="config.html">Learn how configuration works &#x2192;</a> </p>
468</section>
469
470<a id="Getting_Started_Where_to_go_next"></a><section id="Getting_Started_Where_to_go_next"><a id="Where_to_go_next"></a>
471<h1>Where to go next</h1>
472
473<p>
474You'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>
475
476
477<ul>
478
479<li><a href="checks.html">Browse Checks</a> to see the rules Checkstyle provides.</li>
480
481<li><a href="config.html">Configuration</a> explains how to enable checks and change their properties.</li>
482
483<li><a href="config_filters.html">Suppressions and Filters</a> let you handle intentional exceptions.</li>
484
485<li><a href="running.html">Running Checkstyle</a> documents command-line and Ant execution in detail.</li>
486
487<li>IDE integrations can provide faster feedback while you write code. See <a href="index.html#Related_Tools_Active_Tools">Active Tools</a>.</li>
488
489<li>Maven and Gradle integrations can make Checkstyle part of your regular build and CI process.</li>
490</ul>
491
492
493<p>
494For most projects, keep the Checkstyle configuration in version control so developers and automated builds use the same rules. </p>
495</section>
496
497
498        </main>
499      </div>
500    </div>
501    <hr/>
502    <footer>
503      <div class="container-fluid">
504        <div class="row-fluid">
505            <p>©      2001–2026
506</p>
507        </div>
508      </div>
509    </footer>
510  </body>
511</html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.