Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven: Inconsistent formatting of Java (google AOSP style) with plugin and google-java-format.jar #2071

Open
serpro69 opened this issue Mar 19, 2024 · 0 comments

Comments

@serpro69
Copy link

serpro69 commented Mar 19, 2024

Summary

I have google-java-format intellij plugin installed and configured to use AOSP style, and spotless maven plugin that is configured with AOSP as well.
The versions of both the intellij plugin and the google-java-format version in spotless are the same, so it's unlikely this is a version discrepancy.
Reformatting code in intellij makes the plugin report formatting issues:

[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.39.0:check (default) on project template-spring-boot: The following files had format violations:
[ERROR]     src/main/java/no/wlcm/tech/config/OpenApiConfig.java
[ERROR]         @@ -6,12 +6,10 @@
[ERROR]          import·io.swagger.v3.oas.models.security.SecurityRequirement;
[ERROR]          import·io.swagger.v3.oas.models.security.SecurityScheme;
[ERROR]          import·io.swagger.v3.oas.models.servers.Server;
[ERROR]         -
[ERROR]         +import·java.util.stream.Stream;
[ERROR]          import·org.springframework.context.annotation.Bean;
[ERROR]          import·org.springframework.context.annotation.Configuration;
[ERROR]
[ERROR]         -import·java.util.stream.Stream;
[ERROR]         -
[ERROR]          @Configuration
[ERROR]          public·class·OpenApiConfig·{
[ERROR]
[ERROR] Run 'mvn spotless:apply' to fix these violations.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

This is also the diff after running mvn spotless:apply

@@ -6,12 +6,10 @@ import io.swagger.v3.oas.models.info.Info;
 import io.swagger.v3.oas.models.security.SecurityRequirement;
 import io.swagger.v3.oas.models.security.SecurityScheme;
 import io.swagger.v3.oas.models.servers.Server;
-
+import java.util.stream.Stream;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;

-import java.util.stream.Stream;
-
 @Configuration
 public class OpenApiConfig {

As an extra test, I downloaded the google-java-format jar for v1.21.0 ran java -jar /tmp/google-java-format-1.21.0-all-deps.jar -r --aosp OpenApiConfig.java and it does no modifications after reformatting with intellij plugin:

➜ java -jar /tmp/google-java-format-1.21.0-all-deps.jar --aosp OpenApiConfig.java
package foo;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.stream.Stream;

// rest omitted for brevity

So this hints at the spotless plugin, either something it does beyond applying google-java-format, misconfiguration or?

System Info

➜ ./mvnw -version
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /home/sergio/.m2/wrapper/dists/apache-maven-3.9.5-bin/32db9c34/apache-maven-3.9.5
Java version: 17.0.10, vendor: Eclipse Adoptium, runtime: /home/sergio/.sdkman/candidates/java/17.0.10-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.6.10-76060610-generic", arch: "amd64", family: "unix"

➜ lsb_release -a
No LSB modules are available.
Distributor ID: Pop
Description:    Pop!_OS 22.04 LTS
Release:        22.04
Codename:       jammy

Plugin Info

            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>2.39.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <phase>validate</phase>
                    </execution>
                </executions>
                <configuration>
                    <formats>
                        <format>
                            <includes>
                                <include>*.md</include>
                                <include>.gitignore</include>
                            </includes>
                            <trimTrailingWhitespace/>
                            <endWithNewline/>
                            <indent>
                                <spaces>true</spaces>
                                <spacesPerTab>4</spacesPerTab>
                            </indent>
                        </format>
                    </formats>
                    <java>
                        <googleJavaFormat>
                            <version>1.21.0</version>
                            <style>AOSP</style>
                            <reflowLongStrings>true</reflowLongStrings>
                        </googleJavaFormat>
                        <removeUnusedImports/>
                        <formatAnnotations/>
                    </java>
                </configuration>
            </plugin>

Tried to minimize the java format configuration to:

                    <java>
                        <googleJavaFormat>
                            <version>${google-java-format.version}</version>
                            <style>AOSP</style>
                        </googleJavaFormat>
                    </java>

but that produces the same results

@serpro69 serpro69 changed the title Maven: Inconsistent behavior between google java style of plugin and intellij Maven: Inconsistent behavior between formatting Java (google AOSP style) with plugin and intellij Mar 19, 2024
@serpro69 serpro69 changed the title Maven: Inconsistent behavior between formatting Java (google AOSP style) with plugin and intellij Maven: Inconsistent formatting of Java (google AOSP style) with plugin and intellij Mar 19, 2024
@serpro69 serpro69 changed the title Maven: Inconsistent formatting of Java (google AOSP style) with plugin and intellij Maven: Inconsistent formatting of Java (google AOSP style) with plugin and google-java-format.jar Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant