Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 357
John Lippson Avatar asked Oct 14 '25 15:10

John Lippson


1 Answers

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>
like image 176
Guillem Avatar answered Oct 17 '25 05:10

Guillem