Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Attention To

Navigation

Table of Contents
absoluteUrltrue

...

Contributing To AAI By Assisting with Maven Warnings


Contributions Coding Style

See also:

ONAP projects are built using maven and include the "checkstyle" plugin that is configured by the "oparent" module.

Developers can see the output of the "checkstyle" audit by explicitly triggering the phase with "mvn process-sources".

Most of the warnings from the "checkstyle" audit are considered to be "Low" priority (as per the JIRA case definitions Tracking Issues with JIRA#JIRAPriorityDefinitionforBugs) and many PTLs do not want to be flooded with these reviews while there are more urgent and important cases to finish.

However, the volume of the warnings can mask real problems, so it is still useful to resolve the underlying issues. Using the tools mentioned below could be a way to resolve many "checkstyle" warnings quickly, efficiently and consistently across the ONAP projects.

Referring to aai-common/pom.xml as configuration for the sub-components:

Code Block
languagexml
titleaai-common/pom.xml
collapsetrue
                <!--
                Using https://code.revelc.net/formatter-maven-plugin/ for Eclipse formatter
                Using https://github.com/diffplug/spotless/tree/master/plugin-maven for import order
                Use in combination to rewrite code and imports, then checkstyle
                
                mvn formatter:format spotless:apply process-sources
                -->
                <plugin>
                     <groupId>net.revelc.code.formatter</groupId>
                     <artifactId>formatter-maven-plugin</artifactId>
                     <version>2.8.1</version>
                     <configuration>
                        <configFile>${project.parent.basedir}/onap-java-formatter.xml</configFile>
                     </configuration>
                     <!-- https://code.revelc.net/formatter-maven-plugin/
                          use mvn formatter:format to rewrite source files
                          use mvn formatter:validate to validate source files -->
                 </plugin>
                <plugin>
                  <groupId>com.diffplug.spotless</groupId>
                  <artifactId>spotless-maven-plugin</artifactId>
                  <version>1.18.0</version>
                  <configuration>
                    <java>
                     <importOrder>
                       <order>com,java,javax,org</order>
                     </importOrder>
                    </java>
                  </configuration>
                <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven
                     use mvn spotless:apply to rewrite source files
                     use mvn spotless:check to validate source files -->
                </plugin>

...

The "com.diffplug.spotless" plugin also has other language capabilities, which could be useful as well, e.g. Javascript, JSON, YAML, etc, as well as a modular way to add more FormatterSteps.

After using the plugins to rewrite the source files, developers should choose which ones to commit to the repository. There will be several "checkstyle" warnings remaining that cannot be automatically rewritten, so the developers can focus on fixing those few items manually.

Other projects will be able to use this solution by:

  • copying the pom.xml plugin configuration into their own pom.xml (or refer to it from a common module like oparent)
  • copying the "onap-java-formatter.xml" file into their own code repositories (or refer to it from a common module like oparent)
  • training developers to make use of the plugins