在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Cosium/git-code-format-maven-plugin开源软件地址(OpenSource Url):https://github.com/Cosium/git-code-format-maven-plugin开源编程语言(OpenSource Language):Java 99.1%开源软件介绍(OpenSource Introduction):Git Code Format Maven PluginA maven plugin that automatically deploys google-java-format code formatter as a Breaking changes between 2.x and 3.x
Breaking changes between 1.x and 2.x
Automatic code format and validation activationAdd this to your maven project root pom.xml : <build>
<plugins>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>${git-code-format-maven-plugin.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> Manual code formattingmvn git-code-format:format-code -Dgcf.globPattern=**/* Manual code format validationmvn git-code-format:validate-code-format -Dgcf.globPattern=**/* Google Java Format optionsThe plugin allows you to tweak Google Java Format options : <build>
<plugins>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>${git-code-format-maven-plugin.version}</version>
<executions>
<!-- ... -->
</executions>
<configuration>
<googleJavaFormatOptions>
<aosp>false</aosp>
<fixImportsOnly>false</fixImportsOnly>
<skipSortingImports>false</skipSortingImports>
<skipRemovingUnusedImports>false</skipRemovingUnusedImports>
</googleJavaFormatOptions>
</configuration>
</plugin>
</plugins>
</build> Documentation from the google-java-format CLI tool :
JDK 16+ peculiaritiesSince google-java-format uses JDK internal apis, if you need to run the plugin with JDK 16+, you must pass some additional arguments to the JVM. Those are described at https://github.com/google/google-java-format/releases/tag/v1.10.0. Thanks to https://maven.apache.org/configure.html#mvn-jvm-config-file, you should be able to pass them to
Frequently asked questionsIf I have a multi-module project, do I need to install anything in the sub-projects?You only need to put the plugin in your root project pom.xml. By default all submodules will be handled. Do I need to run mvn initialize or is that a stage that happens automatically when I run mvn compile or mvn test?
I'm not noticing anything happening.If after setting up the plugin in your pom, you just executed a maven goal, the only expected output is a pre-commit hook installed in your I'd like to skip code formatting in a child projectI inherit an enterprise parent pom, which I cannot modify, with formatting plugin specified, and I need to turn off formatting for my group's project.
Either use add a How the hook worksOn the #!/bin/bash
"./.git/hooks/${project.artifactId}.git-code-format.pre-commit.sh" and #!/bin/bash
set -e
"${env.M2_HOME}/bin/mvn" -f "${project.basedir}/pom.xml" git-code-format:on-pre-commit On Advanced pre-commit pipeline hookIf you wish to modify the output of the pre-commit hook, you can set the To completely ignore the hook output, you could use the following configuration: <configuration>
<preCommitHookPipeline>>/dev/null</preCommitHookPipeline>
</configuration> To display error lines from the maven output and fail build with any errors, you could use the following configuration: <configuration>
<preCommitHookPipeline>| grep -F '[ERROR]' || exit 0 && exit 1</preCommitHookPipeline>
</configuration> |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论