John Lippson
John Lippson

Reputation: 1319

Maven plugin for auto formatting code to match google checkstyle?

I'm using the google checkstyle in Intellij: https://github.com/google/styleguide

I have this eclipse checkstyle run when I format during any coding in IntelliJ and it seems to work fine. I want to have a Maven phase that formats the code whenever I run mvn clean install.

I'm using the following plugin:

<plugin>
    <groupId>net.revelc.code.formatter</groupId>
    <artifactId>formatter-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>format</goal>
            </goals>
            <configuration>
                <configFile>src/main/resources/eclipse-java-google-style.xml</configFile>
                <encoding>UTF-8</encoding>
            </configuration>
        </execution>
    </executions>
</plugin>

Unfortunately, it doesn't seem to be registering that config file properly. I'm wondering what the best rule of thumb is for grabbing the proper checkstyle config. Where to I put it and how do I represent it in my POM?

Upvotes: 3

Views: 16127

Answers (1)

Guillem
Guillem

Reputation: 466

According to formatter-maven-plugin documentation's example "Basic configuration using external resource", you have to remove the "src/main/resources/" in :

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
    <execution>
        <goals>
            <goal>format</goal>
        </goals>
        <configuration>
            <configFile>eclipse-java-google-style.xml</configFile>
            <encoding>UTF-8</encoding>
        </configuration>
    </execution>
</executions>
</plugin>

Upvotes: 14

Related Questions