### Build google-java-format from Source Source: https://github.com/google/google-java-format/blob/master/README.md This command line snippet shows how to build the google-java-format project from its source code using Maven. Running 'mvn install' compiles the project, executes tests, and installs the resulting artifacts into the local Maven repository. ```Shell mvn install ``` -------------------------------- ### Run google-java-format from Command Line Source: https://github.com/google/google-java-format/blob/master/README.md This snippet demonstrates how to execute the google-java-format JAR from the command line. It requires a JDK (not JRE) with a version equal to or newer than the Java language version of the files being formatted. The tool can reformat whole files, specific lines, or offsets, outputting to standard-out by default or altering files in-place. ```Java java -jar /path/to/google-java-format-${GJF_VERSION?}-all-deps.jar [files...] ``` -------------------------------- ### Build Google Java Format Eclipse Plugin Source: https://github.com/google/google-java-format/blob/master/eclipse_plugin/README.md This command builds the Eclipse plugin, first copying dependencies to `eclipse_plugin/lib/` and then triggering the Tycho build. An alternative command is provided for adding the build artifact to the local Maven repository, with a note on potential issues with outdated artifacts. ```Maven mvn clean package ``` ```Maven mvn clean install -Dtycho.localArtifacts=ignore ``` -------------------------------- ### Apache License, Version 2.0 Source: https://github.com/google/google-java-format/blob/master/README.md This snippet provides the full text of the Apache License, Version 2.0. It outlines the terms and conditions under which the software is provided, including permissions for use, modification, and distribution, along with disclaimers of warranty. ```Text Copyright 2015 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Format Java Source from CharSource to CharSink Source: https://github.com/google/google-java-format/blob/master/README.md This Java snippet demonstrates an alternative method for formatting Java source code using CharSource for input and CharSink for output. The Formatter's formatSource method processes the input from a CharSource and writes the formatted result to a CharSink. ```Java CharSource source = ... CharSink output = ... new Formatter().formatSource(source, output); ``` -------------------------------- ### Configure IntelliJ JVM Options for google-java-format Plugin Source: https://github.com/google/google-java-format/blob/master/README.md To enable the google-java-format plugin in IntelliJ IDEA or Android Studio, specific JVM options must be added to the IDE's custom VM options. These options export internal `jdk.compiler` packages, which are necessary for the plugin to access compiler APIs and function correctly. After adding these lines, the IDE must be restarted. ```Java --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=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.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED ``` -------------------------------- ### Add google-java-format as Maven Dependency Source: https://github.com/google/google-java-format/blob/master/README.md This XML snippet demonstrates how to include the google-java-format library as a dependency in a Maven project's pom.xml. Adding this dependency makes the formatter's functionalities available for use within the project. ```XML com.google.googlejavaformat google-java-format ${google-java-format.version} ``` -------------------------------- ### Configure JVM Flags for google-java-format on JDK 16+ Source: https://github.com/google/google-java-format/blob/master/README.md These JVM flags are essential when running google-java-format on JDK 16 and newer. They address JEP 396 by exporting internal javac APIs, which the formatter uses for parsing Java source, ensuring compatibility and proper functionality. ```Shell --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=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 ``` -------------------------------- ### Format Java Source String using Formatter Source: https://github.com/google/google-java-format/blob/master/README.md This Java snippet shows how to format a Java source code string using the Formatter class. An instance of Formatter is created, and its formatSource method is called with the unformatted string, returning the formatted output. ```Java String formattedSource = new Formatter().formatSource(sourceString); ``` -------------------------------- ### Add google-java-format as Gradle Dependency Source: https://github.com/google/google-java-format/blob/master/README.md This Groovy snippet illustrates how to declare google-java-format as an implementation dependency in a Gradle build script. This configuration ensures that the library is available for compilation and runtime within the Gradle project. ```Groovy dependencies { implementation 'com.google.googlejavaformat:google-java-format:$googleJavaFormatVersion' } ``` -------------------------------- ### Update Eclipse Bundle Version for Plugin Development Source: https://github.com/google/google-java-format/blob/master/eclipse_plugin/README.md Before building the Eclipse plugin, this Maven command updates the bundle version in `META-INF/MANIFEST.MF` to ensure correct versioning for the build process. ```Maven mvn tycho-versions:update-eclipse-metadata ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.