Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing Code Style in Maven

How can I enforce Code Style checks at Maven build-time?

In particular, I'd like to configure both Maven build to use both of these:

  • CheckStyle (https://code.google.com/p/google-api-java-client/source/browse/checkstyle.xml)
  • Code Style (https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml)

How can I configure my Maven build to fail on a Code Style violation?

like image 583
Kevin Meredith Avatar asked Nov 11 '22 12:11

Kevin Meredith


1 Answers

When you configure your plugin in the pom.xml, you should be able to set the failOnViolation.

Maven check style as a part of the build

Edit:

Ah I see... That I know of, Google Code Style plugin doesn't exist for Maven. I guess I would consider writing your own maven plugin that would do something similar to the checkstyle plugin.

https://maven.apache.org/guides/introduction/introduction-to-plugins.html and https://maven.apache.org/plugins/maven-checkstyle-plugin/source-repository.html

Edit 2:

I guess another option would be to find a way to convert your IntelliJ Codestyle xml into a checkstyle xml and then use the maven-checkstyle-plugin to fail based on those rules.

like image 143
jmcmahon Avatar answered Nov 14 '22 22:11

jmcmahon