How to get similar google java formatting in intellij and with maven

459 Views Asked by At

I'd like to have the google java formatting in my IDE (using the google-java-format plugin for IntelliJ or something else if that's not the best way to do...) and be able to check with maven that formatting is OK (in a GitHub workflow for example). I tried the spotless plugin.

Unfortunately for the moment, the results are completely different if I use one or the other (imports order, parameters in methods, ...). I use the AOSP format to get 4 spaces indentation in both case.

Here is my spotless config:

               <plugin>
                    <groupId>com.diffplug.spotless</groupId>
                    <artifactId>spotless-maven-plugin</artifactId>
                    <version>2.30.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <java>
                            <googleJavaFormat>
                                <version>1.7</version>
                                <style>AOSP</style>
                            </googleJavaFormat>
                            <removeUnusedImports />
                            <licenseHeader>
                                <file>../license-header</file>
                            </licenseHeader>
                        </java>
                    </configuration>
                </plugin>

Am I missing something? Aren't they supposed to work with google format (which should be the same...)? Actually I'm not sure Intellij is applying the formatting from the google plugin and not from my other code style configuration. "Enable google-java-format" is checked in the settings, but how to be sure?

0

There are 0 best solutions below