Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override google-java-format with spotless-maven plugin

I'm looking to implement a pre-commit automatic formatter for my team because the code is a bit all over the place. I like spotless and the google style but a sticking point seems to be 4-space indents, whereas it's currently outputting 2-space indents.

Is there a way to override this value via pom.xml, either on spotless side or the google side?

like image 962
Alex Cardell Avatar asked Apr 25 '18 17:04

Alex Cardell


1 Answers

As instructed in Github issue comments here: https://github.com/diffplug/spotless/issues/420

You can solve this in Gradle build with:

indentWithTabs(2)
indentWithSpaces(4)

For Maven the same code would be:

    <java>
        <googleJavaFormat>
            <version>1.8</version>
            <style>GOOGLE</style>
        </googleJavaFormat>
        <indent>
            <tabs>true</tabs>
            <spacesPerTab>2</spacesPerTab>
        </indent>
        <indent>
            <spaces>true</spaces>
            <spacesPerTab>4</spacesPerTab>
        </indent>
    </java>
like image 169
Hannu Varjoranta Avatar answered Sep 28 '22 05:09

Hannu Varjoranta