{"id":13401637,"url":"https://github.com/google/google-java-format","last_synced_at":"2025-09-09T21:14:26.618Z","repository":{"id":31880329,"uuid":"35448780","full_name":"google/google-java-format","owner":"google","description":"Reformats Java source code to comply with Google Java Style.","archived":false,"fork":false,"pushed_at":"2025-04-14T19:13:18.000Z","size":2137,"stargazers_count":5779,"open_issues_count":152,"forks_count":885,"subscribers_count":134,"default_branch":"master","last_synced_at":"2025-05-05T20:26:05.998Z","etag":null,"topics":["formatter","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null}},"created_at":"2015-05-11T20:38:28.000Z","updated_at":"2025-05-04T06:24:14.000Z","dependencies_parsed_at":"2023-10-05T06:39:06.280Z","dependency_job_id":"8d9fad7b-875b-4a26-957f-a7095f8d1d65","html_url":"https://github.com/google/google-java-format","commit_stats":{"total_commits":723,"total_committers":97,"mean_commits":7.453608247422681,"dds":0.3706777316735823,"last_synced_commit":"685a6c9ebd43aab9ef458379de7d3883bfee970f"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fgoogle-java-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fgoogle-java-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fgoogle-java-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fgoogle-java-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/google-java-format/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253929199,"owners_count":21985799,"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":["formatter","java"],"created_at":"2024-07-30T19:01:05.033Z","updated_at":"2025-05-13T10:52:06.859Z","avatar_url":"https://github.com/google.png","language":"Java","readme":"# google-java-format\n\n`google-java-format` is a program that reformats Java source code to comply with\n[Google Java Style][].\n\n[Google Java Style]: https://google.github.io/styleguide/javaguide.html\n\n## Using the formatter\n\n### From the command-line\n\n[Download the formatter](https://github.com/google/google-java-format/releases)\nand run it with:\n\n```\njava -jar /path/to/google-java-format-${GJF_VERSION?}-all-deps.jar \u003coptions\u003e [files...]\n```\n\nNote that it uses the `jdk.compiler` module to parse the Java source code. The\n`java` binary version used must therefore be from a JDK (not JRE) with a version\nequal to or newer than the Java language version of the files being formatted.\nThe minimum Java version can be found in `core/pom.xml` (currently Java 17). An\nalternative is to use the available GraalVM based native binaries instead.\n\nThe formatter can act on whole files, on limited lines (`--lines`), on specific\noffsets (`--offset`), passing through to standard-out (default) or altered\nin-place (`--replace`).\n\nTo reformat changed lines in a specific patch, use\n[`google-java-format-diff.py`](https://github.com/google/google-java-format/blob/master/scripts/google-java-format-diff.py).\n\n***Note:*** *There is no configurability as to the formatter's algorithm for\nformatting. This is a deliberate design decision to unify our code formatting on\na single format.*\n\n### IntelliJ, Android Studio, and other JetBrains IDEs\n\nA\n[google-java-format IntelliJ plugin](https://plugins.jetbrains.com/plugin/8527)\nis available from the plugin repository. To install it, go to your IDE's\nsettings and select the `Plugins` category. Click the `Marketplace` tab, search\nfor the `google-java-format` plugin, and click the `Install` button.\n\nThe plugin will be disabled by default. To enable,\n[open the Project settings](https://www.jetbrains.com/help/idea/configure-project-settings.html),\nthen click \"google-java-format Settings\" and check the \"Enable\ngoogle-java-format\" checkbox.\n\nTo enable it by default in new projects,\n[open the default settings for new projects](https://www.jetbrains.com/help/idea/configure-project-settings.html#new-default-settings)\nand configure it under \"Other Settings/google-java-format Settings\".\n\nWhen enabled, it will replace the normal `Reformat Code` and `Optimize Imports`\nactions.\n\n#### IntelliJ JRE Config\n\nThe google-java-format plugin uses some internal classes that aren't available\nwithout extra configuration. To use the plugin, you need to\n[add some options to your IDE's Java runtime](https://www.jetbrains.com/help/idea/tuning-the-ide.html#procedure-jvm-options).\nTo do that, go to `Help→Edit Custom VM Options...` and paste in these lines:\n\n```\n--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED\n```\n\nOnce you've done that, restart the IDE.\n\n### Eclipse\n\nThe latest version of the `google-java-format` Eclipse plugin can be downloaded\nfrom the [releases page](https://github.com/google/google-java-format/releases).\nDrop it into the Eclipse\n[drop-ins folder](http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fp2_dropins_format.html)\nto activate the plugin.\n\nThe plugin adds a `google-java-format` formatter implementation that can be\nconfigured in `Window \u003e Preferences \u003e Java \u003e Code Style \u003e Formatter \u003e Formatter\nImplementation`.\n\n### Third-party integrations\n\n*   Visual Studio Code\n    *   [google-java-format-for-vs-code](https://marketplace.visualstudio.com/items?itemName=JoseVSeb.google-java-format-for-vs-code)\n*   Gradle plugins\n    *   [spotless](https://github.com/diffplug/spotless/tree/main/plugin-gradle#google-java-format)\n    *   [sherter/google-java-format-gradle-plugin](https://github.com/sherter/google-java-format-gradle-plugin)\n*   Apache Maven plugins\n    *   [spotless](https://github.com/diffplug/spotless/tree/main/plugin-maven#google-java-format)\n    *   [spotify/fmt-maven-plugin](https://github.com/spotify/fmt-maven-plugin)\n    *   [talios/googleformatter-maven-plugin](https://github.com/talios/googleformatter-maven-plugin)\n    *   [Cosium/maven-git-code-format](https://github.com/Cosium/maven-git-code-format):\n        A maven plugin that automatically deploys google-java-format as a\n        pre-commit git hook.\n*   SBT plugins\n    *   [sbt/sbt-java-formatter](https://github.com/sbt/sbt-java-formatter)\n*   [Github Actions](https://github.com/features/actions)\n    *   [googlejavaformat-action](https://github.com/axel-op/googlejavaformat-action):\n        Automatically format your Java files when you push on github\n\n### as a library\n\nThe formatter can be used in software which generates java to output more\nlegible java code. Just include the library in your maven/gradle/etc.\nconfiguration.\n\n`google-java-format` uses internal javac APIs for parsing Java source. The\nfollowing JVM flags are required when running on JDK 16 and newer, due to\n[JEP 396: Strongly Encapsulate JDK Internals by Default](https://openjdk.java.net/jeps/396):\n\n```\n--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED\n--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED\n```\n\n#### Maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.google.googlejavaformat\u003c/groupId\u003e\n  \u003cartifactId\u003egoogle-java-format\u003c/artifactId\u003e\n  \u003cversion\u003e${google-java-format.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Gradle\n\n```groovy\ndependencies {\n  implementation 'com.google.googlejavaformat:google-java-format:$googleJavaFormatVersion'\n}\n```\n\nYou can then use the formatter through the `formatSource` methods. E.g.\n\n```java\nString formattedSource = new Formatter().formatSource(sourceString);\n```\n\nor\n\n```java\nCharSource source = ...\nCharSink output = ...\nnew Formatter().formatSource(source, output);\n```\n\nYour starting point should be the instance methods of\n`com.google.googlejavaformat.java.Formatter`.\n\n## Building from source\n\n```\nmvn install\n```\n\n## Contributing\n\nPlease see [the contributors guide](CONTRIBUTING.md) for details.\n\n## License\n\n```text\nCopyright 2015 Google Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n```\n","funding_links":[],"categories":["Java","Programming Languages","\u003ca name=\"Java\"\u003e\u003c/a\u003eJava","Language Specific"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fgoogle-java-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Fgoogle-java-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fgoogle-java-format/lists"}