- The Maven Checkstyle Plugin is a programmatic means of validating source code style conformity
- The
rev_checks.xml
describes the set of rules which Checkstyle will be enforcing, with Markdown examples found here - You must apply the
pom.xml
Setup- The choice is yours to configure your IDE; It can assist with actions such as
auto-formatting
- The choice is yours to configure your IDE; It can assist with actions such as
- Create (or update the existing)
<properties>
(Example found at line 10)- Copy the following properties to your
pom.xml
<properties> <!-- ... other properties --> <checkstyle-maven-plugin.version>3.1.1</checkstyle-maven-plugin.version> <puppycrawl-checkstyle.version>8.29</puppycrawl-checkstyle.version> </properties>
- Copy the following properties to your
- Create (or update the existing)
<build>
tags with the following plugin (Example found at line 25)<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>${checkstyle-maven-plugin.version}</version> <!-- Note use of property --> <configuration> <configLocation>rev_checks.xml</configLocation> <!-- Can vary based on the location on your machine --> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <failsOnError>true</failsOnError> <linkXRef>false</linkXRef> </configuration> <executions> <execution> <id>validate</id> <phase>validate</phase> <goals> <goal>check</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>com.puppycrawl.tools</groupId> <artifactId>checkstyle</artifactId> <version>${puppycrawl-checkstyle.version}</version> <!-- Note use of property --> </dependency> </dependencies> </plugin> </plugins>
- Create (or update the existing)
<reporting>
tag with the following plugin<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>${checkstyle-maven-plugin.version}</version> <!-- Note use of property --> <configuration> <configLocation>rev_checks.xml</configLocation> <!-- Can vary based on the location on your machine --> </configuration> </plugin> </plugins>
- Eclipse/STS
- Download and Install this plugin to your local instance
- To get to the appropriate menu, navigate to
Help -> Eclipse Marketplace
- Restart the IDE as needed
- To get to the appropriate menu, navigate to
- To import our configuration, navigate to
Windows -> Preferences -> Checkstyle
- Create a
New
configuration- Supply the name
Revature Checks
- Click the Import button to open a wizard to select the filepath
- Supply the name
- Click on the newly created configuration and then mark
Set as Default
- Apply and Close!
- Download and Install this plugin to your local instance
- VS Code
- Download and Install this plugin to your local instance
- Once installed, copy over the
rev_checks.xml
to your project's root directory- Right click on the
rev_checks.xml
file and select Set the Checkstyle Configuration File
- Right click on the
- IntelliJ
- Download and Install this plugin to your local instance
- Navigate to
File -> Settings -> Editor -> Code Style
- Find the gear icon, click on it and select Import Scheme
- (Optional) Choose to apply this setting as the IDE Default or scoped to the current project