{"id":25932777,"url":"https://github.com/cosium/git-code-format-maven-plugin","last_synced_at":"2026-03-05T11:05:36.991Z","repository":{"id":39749621,"uuid":"109197588","full_name":"Cosium/git-code-format-maven-plugin","owner":"Cosium","description":"A maven plugin that automatically deploys code formatters as pre-commit git hook","archived":false,"fork":false,"pushed_at":"2025-04-07T15:35:10.000Z","size":386,"stargazers_count":212,"open_issues_count":13,"forks_count":40,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T01:48:18.044Z","etag":null,"topics":["code-formatter","git","google-java-format","hook","java","maven"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cosium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-02T00:10:38.000Z","updated_at":"2025-04-07T15:34:22.000Z","dependencies_parsed_at":"2023-10-02T13:02:22.295Z","dependency_job_id":"c7aa0b92-4f09-4f9e-b297-14f5d9d6e306","html_url":"https://github.com/Cosium/git-code-format-maven-plugin","commit_stats":null,"previous_names":["cosium/maven-git-code-format"],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosium%2Fgit-code-format-maven-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosium%2Fgit-code-format-maven-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosium%2Fgit-code-format-maven-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosium%2Fgit-code-format-maven-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cosium","download_url":"https://codeload.github.com/Cosium/git-code-format-maven-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525770,"owners_count":21118749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-formatter","git","google-java-format","hook","java","maven"],"created_at":"2025-03-04T00:39:06.555Z","updated_at":"2026-01-11T17:39:31.940Z","avatar_url":"https://github.com/Cosium.png","language":"Java","readme":"[![Maven Central Latest](https://img.shields.io/maven-central/v/com.cosium.code/git-code-format-maven-plugin.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.cosium.code%22%20AND%20a%3A%22git-code-format-maven-plugin%22)\n[![Build Status](https://github.com/Cosium/git-code-format-maven-plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/Cosium/git-code-format-maven-plugin/actions/workflows/ci.yml)\n\n# Git Code Format Maven Plugin\n\nA maven plugin that automatically deploys code formatters as `pre-commit` git hook.\nOn commit, the hook will automatically format staged files.\n\n# Breaking changes between 4.x and 5.x\n\n* If the plugin runs without any formatter dependency, it will fail. This is done to prevent silent misconfiguration from happening.\n\n# Breaking changes between 3.x and 4.x\n\n* `Google Java Format` is not enabled by default anymore. `com.cosium.code:google-java-format` must be added as a dependency to the plugin to keep using it.\n* `Google Java Format` options declaration structure has changed. You will need to migrate any eventual existing declaration to the new structure described by [the google-java-format-options chapter](#google-java-format-options) .\n\n# Breaking changes between 2.x and 3.x\n\n* [#64](https://github.com/Cosium/git-code-format-maven-plugin/issues/64) `google-java-format 1.8` [dropped support for java 8](https://github.com/google/google-java-format/releases/tag/google-java-format-1.8).\n  The minimum supported runtime version for the plugin is JDK 11. i.e. Maven must run on JDK 11+ while the target project can still be built and run using JDK 8.\n\n# Breaking changes between 1.x and 2.x\n\n* [#37](https://github.com/Cosium/git-code-format-maven-plugin/issues/37) To prevent conflicts with other plugins all keys are now \nprefixed with `gcf`. e.g. `-DglobPattern=**/*` becomes `-Dgcf.globPattern=**/*`\n* [#38](https://github.com/Cosium/git-code-format-maven-plugin/issues/38) To avoid infringement to Apache Maven Trademark, \nthe plugin was renamed to `git-code-format-maven-plugin`. Its new coordinates are \n`com.cosium.code:git-code-format-maven-plugin`.\n\n`1.x` documentation can be found [here](https://github.com/Cosium/git-code-format-maven-plugin/blob/1.39/README.md)\n\n# Automatic code format and validation activation\n\nAdd this to your maven project **root** pom.xml :\n\n```xml\n\u003cbuild\u003e\n  \u003cplugins\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003ecom.cosium.code\u003c/groupId\u003e\n      \u003cartifactId\u003egit-code-format-maven-plugin\u003c/artifactId\u003e\n      \u003cversion\u003e${git-code-format-maven-plugin.version}\u003c/version\u003e\n      \u003cexecutions\u003e\n        \u003c!-- On commit, format the modified files --\u003e\n        \u003cexecution\u003e\n          \u003cid\u003einstall-formatter-hook\u003c/id\u003e\n          \u003cgoals\u003e\n            \u003cgoal\u003einstall-hooks\u003c/goal\u003e\n          \u003c/goals\u003e\n        \u003c/execution\u003e\n        \u003c!-- On Maven verify phase, fail if any file\n        (including unmodified) is badly formatted --\u003e\n        \u003cexecution\u003e\n          \u003cid\u003evalidate-code-format\u003c/id\u003e\n          \u003cgoals\u003e\n            \u003cgoal\u003evalidate-code-format\u003c/goal\u003e\n          \u003c/goals\u003e\n        \u003c/execution\u003e\n      \u003c/executions\u003e\n      \u003cdependencies\u003e\n        \u003c!-- Enable https://github.com/google/google-java-format --\u003e\n        \u003cdependency\u003e\n          \u003cgroupId\u003ecom.cosium.code\u003c/groupId\u003e\n          \u003cartifactId\u003egoogle-java-format\u003c/artifactId\u003e\n          \u003cversion\u003e${git-code-format-maven-plugin.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n      \u003c/dependencies\u003e\n    \u003c/plugin\u003e\n  \u003c/plugins\u003e\n\u003c/build\u003e\n```\n\n# Manual code formatting\n\n```console\nmvn git-code-format:format-code -Dgcf.globPattern=**/*\n```\n\n# Manual code format validation\n\n```console\nmvn git-code-format:validate-code-format -Dgcf.globPattern=**/*\n```\n\n# Google Java Format\n\n## Google Java Format options\n\nThe plugin allows you to tweak Google Java Format options :\n\n```xml\n\u003cbuild\u003e\n  \u003cplugins\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003ecom.cosium.code\u003c/groupId\u003e\n      \u003cartifactId\u003egit-code-format-maven-plugin\u003c/artifactId\u003e\n      \u003cversion\u003e${git-code-format-maven-plugin.version}\u003c/version\u003e\n      \u003cexecutions\u003e\n        \u003c!-- ... --\u003e\n      \u003c/executions\u003e\n      \u003cdependencies\u003e\n        \u003c!-- ... --\u003e\n      \u003c/dependencies\u003e        \n      \u003cconfiguration\u003e\n        \u003cformatterOptions\u003e\n          \u003c!-- Use AOSP style instead of Google Style (4-space indentation). --\u003e\n          \u003cgoogleJavaFormat.aosp\u003efalse\u003c/googleJavaFormat.aosp\u003e\n          \u003c!-- Format the javadoc --\u003e\n          \u003cgoogleJavaFormat.formatJavadoc\u003etrue\u003c/googleJavaFormat.formatJavadoc\u003e\n          \u003c!-- Fix import order and remove any unused imports, but do no other formatting. --\u003e\n          \u003cgoogleJavaFormat.fixImportsOnly\u003efalse\u003c/googleJavaFormat.fixImportsOnly\u003e\n          \u003c!-- Do not fix the import order. Unused imports will still be removed. --\u003e\n          \u003cgoogleJavaFormat.skipSortingImports\u003efalse\u003c/googleJavaFormat.skipSortingImports\u003e\n          \u003c!-- Do not remove unused imports. Imports will still be sorted. --\u003e\n          \u003cgoogleJavaFormat.skipRemovingUnusedImports\u003efalse\u003c/googleJavaFormat.skipRemovingUnusedImports\u003e\n        \u003c/formatterOptions\u003e\n      \u003c/configuration\u003e\n    \u003c/plugin\u003e\n  \u003c/plugins\u003e\n\u003c/build\u003e\n```\n\n## JDK 16+ peculiarities\n\nSince 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.\nThose are described at https://github.com/google/google-java-format/releases/tag/v1.10.0.  \n\nThanks to https://maven.apache.org/configure.html#mvn-jvm-config-file, you should be able to pass them to `.mvn/jvm.config` as follow:\n\n```\n--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED\n```\n\n# Custom code formatter\n\nThanks to its code formatter SPI, this plugin can execute any code formatter.\n\n## How to\n\nNote that you can take inspiration from the `google-java-format` module of this project.\n\n1. Implement `com.cosium.code.format_spi.CodeFormatterFactory`. This interface is provided by `com.cosium.code:git-code-format-maven-plugin-spi`.\n2. Add your `com.cosium.code.format_spi.CodeFormatterFactory` implementation canonical name in `META-INF/services/com.cosium.code.format_spi.CodeFormatterFactory`.\n3. Pack this in a jar that you declare as a dependency in this plugin declaration.\n\n## Example of usage\n\nSuppose: \n- the chosen `configurationId` (declared by `com.cosium.code.format_spi.CodeFormatterFactory#configurationId()`) is `aqme`\n- the formatter dependency is `com.aqme.formatter:formatter:1.0`\n\nA plugin declaration making use of this custom code formatter would look like this:\n\n```xml\n\u003cbuild\u003e\n  \u003cplugins\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003ecom.cosium.code\u003c/groupId\u003e\n      \u003cartifactId\u003egit-code-format-maven-plugin\u003c/artifactId\u003e\n      \u003cversion\u003e${git-code-format-maven-plugin.version}\u003c/version\u003e\n      \u003cexecutions\u003e\n        \u003c!-- ... --\u003e\n      \u003c/executions\u003e\n      \u003cdependencies\u003e\n        \u003cdependency\u003e\n          \u003cgroupId\u003ecom.aqme.formatter\u003c/groupId\u003e\n          \u003cartifactId\u003eformatter\u003c/artifactId\u003e\n          \u003cversion\u003e1.0\u003c/version\u003e\n        \u003c/dependency\u003e\n      \u003c/dependencies\u003e\n      \u003cconfiguration\u003e\n        \u003cformatterOptions\u003e\n          \u003caqme.option1\u003efalse\u003c/aqme.option1\u003e\n          \u003caqme.option2\u003efoo\u003c/aqme.option2\u003e\n        \u003c/formatterOptions\u003e\n      \u003c/configuration\u003e\n    \u003c/plugin\u003e\n  \u003c/plugins\u003e\n\u003c/build\u003e\n```\n\n# Frequently asked questions\n\n## If I have a multi-module project, do I need to install anything in the sub-projects?\nYou only need to put the plugin in your *root* project pom.xml. By default all submodules will be handled.\n\n## Do I need to run mvn initialize or is that a stage that happens automatically when I run mvn compile or mvn test?\n`initialize` is the first phase of the Maven lifecycle. Any goal that you perform (e.g. `compile` or `test`) will automatically trigger `initialize` and thus trigger the git pre-commit hook installation.\n\n## I'm not noticing anything happening.\nIf 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 `.git/hooks` directory. To trigger the automatic formatting, you have to perform a commit of a modified file.\nYou can also manually [format](#manual-code-formatting) or [validate](#manual-code-format-validation) any file.\n\n## I'd like to skip code formatting in a child project \nI 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.\nEither use add a ```\u003cskip\u003etrue\u003c/skip\u003e``` configuration in the inheriting project or set the ```gcf.skip``` property to true.\n\n# How the hook works\n\nOn the `initialize` maven phase, `git-code-format:install-hooks` installs a git `pre-commit` hook that looks like this :\n```bash\n#!/bin/bash\n\"./.git/hooks/${project.artifactId}.git-code-format.pre-commit.sh\"\n```\nand `.git/hooks/${project.artifactId}.git-code-format.pre-commit.sh` has the following content:\n```bash\n#!/bin/bash\nset -e\n\"${env.M2_HOME}/bin/mvn\" -f \"${project.basedir}/pom.xml\" git-code-format:on-pre-commit\n```\n\nOn `pre-commit` git phase, the hook triggers the `git-code-format:on-pre-commit` which formats the code of the modified files.\n\n# Advanced pre-commit pipeline hook\nIf you wish to modify the output of the pre-commit hook, you can set the `preCommitHookPipeline` configuration.\n\nTo completely ignore the hook output, you could use the following configuration:\n```xml\n      \u003cconfiguration\u003e\n        \u003cpreCommitHookPipeline\u003e\u0026gt;/dev/null\u003c/preCommitHookPipeline\u003e\n      \u003c/configuration\u003e\n```\n\nTo display error lines from the maven output and fail build with any errors, you could use the following configuration:\n```xml\n      \u003cconfiguration\u003e\n        \u003cpreCommitHookPipeline\u003e| grep -F '[ERROR]' || exit 0 \u0026amp;\u0026amp; exit 1\u003c/preCommitHookPipeline\u003e\n      \u003c/configuration\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosium%2Fgit-code-format-maven-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosium%2Fgit-code-format-maven-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosium%2Fgit-code-format-maven-plugin/lists"}