Periodically, checkstyle updates their version and, quite regularly, they introduce changes that are not backwardly compatible. Usually, checkstyle version updates are noticed by developers when the version of the Eclipse checkstyle version steps in Eclipse on an Eclipse software update. It is quite difficult to downgrade the version of a plugin in Eclipse so it is recommended to step the version of Checkstyle in ONAP when Eclipse upgrades its plugin.
In ONAP, we follow the Google Java code style. The checkstyle configuration file for the Google Java style is available here (master version). Each time the version of checkstyle is stepped, a new tagged version of the checkstyle configuration file is made available, see, for example, the configuration file for checkstyle version 8.32 here.
ONAP uses a slightly modified version of the Google style. The differences are:
- Maximum line length is 120 characters instead of 100 characters
- ONAP uses an indent of 4 characters instead of 2
- ONAP does not insist on Javadoc being written for method with names beginning with "test", "before", and "after"
Stepping the version of checkstyle in ONAP is not automatic.A review must be raised on the ONAP oparent project to implement the change. There are three places where configuration changes must be made, and the configurations in all three places must match. In the instructions below, we are stepping the version of checkstyle to 8.32, the version supported by Eclipse at the time of writing. Check out the oparent project from the ONAP gerrit to make the change.
1. Checkstyle plugin in Eclipse
Check the version of the Checkstyle plugin in Eclipse→About Eclipse→Installation Details
2. oparent pom.xml
Modify the the oparent pom.xml file as follows.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>3.1.1</version> <dependencies> <dependency> <groupId>com.puppycrawl.tools</groupId> <artifactId>checkstyle</artifactId> <version>8.32</version> </dependency> </dependencies> </plugin>
2.1 Checkstyle Plugin version
Set the version of the Maven checkstyle plugin in the oparent pom.xml file to a version that supports the version of checkstyle you want to use. See the dependencies for each version in the Maven Repository. For example, in the Compile Dependencies table of version 3.1.1 of the Maven checkstyle plugin, we can see that version 3.1.1 supports checkstyle version 8.29 to 8.33. See the example plugin configuration above.
2.2 Checkstyle version
Set the version of checkstyle for com.puppycrawl.tools.checkstyle to be the version of checkstyle you want to use. In this case, it is set to checkstyle version 8.32.
3. Modify the ONAP onap-java-style.xml file
This file defines the ONAP Java style, and it is a modified version of the Google Java style.
- Download the appropriate version of the Google java style from the checkstyle Github repo.For example, the configuration file for checkstyle version 8.32 here.
Change the maximum line length in the LineLength directive to 120 characters
<module name="LineLength"> <property name="fileExtensions" value="java" /> <property name="max" value="120" /> <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://" /> </module>
Change the indentation in the Indentation directive to 2 spaces
<module name="Indentation"> <property name="basicOffset" value="4" /> <property name="braceAdjustment" value="0" /> <property name="caseIndent" value="4" /> <property name="throwsIndent" value="4" /> <property name="lineWrappingIndentation" value="4" /> <property name="arrayInitIndent" value="4" /> </module>
Change the MissingJavadocMethod directive to Ignore missing Javadoc on test methods
<module name="MissingJavadocMethod"> <property name="scope" value="public" /> <property name="minLineCount" value="2" /> <property name="allowedAnnotations" value="Override, Test" /> <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF" /> <property name="ignoreMethodNamesRegex" value="^(test|before|after)[a-zA-Z0-9_]*$" /> </module>