Java 谷歌代码风格的格式maven pom在Intellij中很奇怪
我在Java项目中使用Google代码样式。我在IntelliJ中安装了GoogleJava格式插件,但该插件没有涵盖所有格式规则(例如java导入)。文档建议在IntelliJ中添加Google样式指南作为代码样式方案。我下载了Java 谷歌代码风格的格式maven pom在Intellij中很奇怪,java,maven,intellij-idea,pom.xml,google-java-format,Java,Maven,Intellij Idea,Pom.xml,Google Java Format,我在Java项目中使用Google代码样式。我在IntelliJ中安装了GoogleJava格式插件,但该插件没有涵盖所有格式规则(例如java导入)。文档建议在IntelliJ中添加Google样式指南作为代码样式方案。我下载了intellijjavagooglestyle.xml,并添加了配置: 如果启用了Google代码样式,导入的格式将如预期的那样,但是我的Maven POM的格式将被破坏 具有默认方案的Maven POM: <project xmlns:xsi="http://
intellijjavagooglestyle.xml
,并添加了配置:
如果启用了Google代码样式,导入的格式将如预期的那样,但是我的Maven POM的格式将被破坏
具有默认方案的Maven POM:
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-git-code-format.version>1.39</maven-git-code-format.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>test.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>maven-git-code-format</artifactId>
<version>${maven-git-code-format.version}</version>
<executions>
<!-- On commit, format the modified java files -->
<execution>
<id>install-formatter-hook</id>
<goals>
<goal>install-hooks</goal>
</goals>
</execution>
<!-- On Maven verify phase, fail if any file
(including unmodified) is badly formatted -->
<execution>
<id>validate-code-format</id>
<goals>
<goal>validate-code-format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.test
测试
1
罐子
11
UTF-8
1.39
org.apache.maven.plugins
maven编译器插件
3.8.1
11
org.apache.maven.plugins
maven jar插件
3.1.2
真的
主测试
com.cosium.code
maven git代码格式
${maven git code format.version}
安装格式化程序挂钩
安装挂钩
验证代码格式
验证代码格式
Maven POM与谷歌方案:
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>test</artifactId>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>11</release>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>test.Main</mainClass>
</manifest>
</archive>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-git-code-format</artifactId>
<executions>
<!-- On commit, format the modified java files -->
<execution>
<goals>
<goal>install-hooks</goal>
</goals>
<id>install-formatter-hook</id>
</execution>
<!-- On Maven verify phase, fail if any file
(including unmodified) is badly formatted -->
<execution>
<goals>
<goal>validate-code-format</goal>
</goals>
<id>validate-code-format</id>
</execution>
</executions>
<groupId>com.cosium.code</groupId>
<version>${maven-git-code-format.version}</version>
</plugin>
</plugins>
</build>
<groupId>com.test</groupId>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<properties>
<java.version>11</java.version>
<maven-git-code-format.version>1.39</maven-git-code-format.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<version>1.0</version>
</project>
测试
maven编译器插件
11
org.apache.maven.plugins
3.8.1
maven jar插件
真的
主测试
org.apache.maven.plugins
3.1.2
maven git代码格式
安装挂钩
安装格式化程序挂钩
验证代码格式
验证代码格式
com.cosium.code
${maven git code format.version}
com.test
4.0.0
罐子
11
1.39
UTF-8
1
XML标记似乎是按字典顺序排序的
有人分享过我的经验并找到了解决我问题的方法吗?我重现了这种行为,它在XML排列选项卡中定义: 排列格式 我想,正如您可以从名称空间定义中看到的那样,xml布局针对android xml布局进行了优化 因此,编码风格是针对android的,其行为符合预期。您可以在导入样式后更改XML布局 因此,pom的格式没有被破坏,只是不同而已。解决方案:只需更改排列,或者不使用这种编码样式 我找到了一个插件来解决这个问题 记住在使用XML排列之前将其设置为默认值