Using the Checkstyle plug-in This tutorial will describe the usage of the Checkstyle plug-in for Eclipse.
Checkstyle is a tool to help ensuring that your Java code adheres to a set of coding standards
http://eclipse-cs.sourceforge.net/update Update site for the Eclipse Checkstyle Plugin.
Please see Eclipse Update Manager for more information on how to use the update manager.
If you developing with Eclipse, make sure to select the Sun Conventions (Eclipse) under
. Press the "Set as Default" after selecting the right entry.
You can turn of certain checks. If you change settings from the standard profile you should always make a copy of the existing profile.
To customizine your check, first make a copy of the checks
Select your new configuration and press Configure. De-activatefor example the checks for Javadoc Comments.
Make this new setting your default one.
1.4. Using common Checkstyle rules for teams
For teams it is good to follow the same coding style rules. The Eclipse checkstyle plug-in allows this by proving a remote site for the checkstyle settings.
Press new in the settings. Select "Remote Configuration". Give the rule set a description and then type in the URL you want to use for the settings.
Make this new setting your default one.
1.5. Using Checkstyle in your projects
Make your new profile the default one. You need to activate the Eclipse Checkstyle Plugin for your project. Right-click on your project and search for Checkstyle. Select the checkbox "Checkstyle active for this project".
You can use the checkstyle browser view to display the violations.
2. Checkstyle Maven Plugin
Checkstyle can also be run during a Maven build. The
can generate reports about checkstyle violations or can also be a part
of the build and cause a build failure when the rules defined in the
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.17</version> <executions> <execution> <id>validate</id> <phase>validate</phase> <configuration> <configLocation>checkstyle.xml</configLocation> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <failsOnError>true</failsOnError> <linkXRef>false</linkXRef> </configuration> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
More information about the usage can be found here: Maven Checkstyle plugin usage
3. Exercise: Use the Checkstyle Maven plugin
The target of this exercise is to check code being build with maven and let the build fail in case rules are violated.
For a introduction to maven please refer to the Apache Maven tutorial.
3.3. Create a maven project
Create a quick start maven project in an IDE or by using the command line like this:
mvn archetype:generate -DgroupId=com.vogella.build.maven.java \ -DartifactId=com.vogella.build.maven.java \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false
3.4. Apply the checkstyle plugin
To activate the maven-checkstyle-plugin it has to be applied to the
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.17</version> <executions> <execution> <id>validate</id> <phase>validate</phase> <configuration> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <failsOnError>true</failsOnError> <linkXRef>false</linkXRef> </configuration> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
mvn clean verify
to see all checkstyle validation failures of the generated project.
4. About this website
5. Links and Literature
5.2. vogella GmbH training and consulting support
|TRAINING||SERVICE & SUPPORT|
The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.
The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.
Appendix A: Copyright and License
Copyright © 2012-2016 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.