diff --git a/.vscode/settings.recommended.json b/.vscode/settings.recommended.json index 96102923c..8750a6894 100644 --- a/.vscode/settings.recommended.json +++ b/.vscode/settings.recommended.json @@ -4,6 +4,8 @@ // formatOnType and formatOnPaste is a very bad idea for slow formatters // (such as an external Google Java Format invocation exec), so just on Save: "editor.formatOnSave": true, + // Format the changed region, not the whole file, as CONTRIBUTING.md asks. + "editor.formatOnSaveMode": "modifications", "editor.formatOnType": false, "editor.formatOnPaste": false, @@ -21,9 +23,8 @@ "source.addMissingImports": "never" } }, - // Keep this version in sync with the same version in pom.xml // NB: Changes to this are only taken into account on start-up, so need to restart. - "java.format.settings.google.version": "1.27.0", + "java.format.settings.google.version": "2.0.0", // TODO https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3050 "java.compile.nullAnalysis.mode": "automatic", "java.completion.importOrder": ["#", "", "javax", "java"], //# is static diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1f1bc64d7..242ebe413 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,14 +37,17 @@ information on using pull requests. ### Format Code must be formatted according to the -[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). +[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html), +using [`google-java-format`](https://github.com/google/google-java-format). +Format only the lines you change, with an IDE integration or with +[`google-java-format-diff.py`](https://github.com/google/google-java-format/blob/master/scripts/google-java-format-diff.py): -The Maven build will automagically run -[`google-java-format`](https://github.com/google/google-java-format) when you -locally build this project. +```shell +git diff -U0 $(git merge-base origin/main HEAD) | google-java-format-diff.py -p1 -i +``` -Pull requests will fail to build if you forget to commit reformatted code, and -cannot be merged until you fix this. +Stage new files with `git add` first. In a fork, use the remote that points at +`google/adk-java` instead of `origin`. ### Single Commit diff --git a/GEMINI.md b/GEMINI.md index 91b780906..7aa64849a 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -51,10 +51,10 @@ The project is built using Maven. Use the `./mvnw` wrapper script for all comman ./mvnw test ``` -* **Format code**: +* **Format changed lines**: ```shell - ./mvnw fmt:format + git diff -U0 $(git merge-base origin/main HEAD) | google-java-format-diff.py -p1 -i ``` * **Skip tests during build**: @@ -91,7 +91,8 @@ Once started, the dev UI is available at `http://localhost:8000` (or the specifi ## Development Conventions -* **Coding Style**: The project follows the Google Java Style Guide. The `fmt-maven-plugin` is used to format the code automatically. +* **Coding Style**: The project follows the Google Java Style Guide. Format + changed lines with `google-java-format`. * **Import Style**: Always use import statements instead of fully qualified class names in code. Prefer `import com.google.adk.agents.InvocationContext;` over using `com.google.adk.agents.InvocationContext` directly in the code. * **Testing**: The project uses JUnit 5 for testing. Tests are located in the `src/test/java` directory of each module. * **Contributing**: Contributions are welcome. Please see the `CONTRIBUTING.md` file for more information. diff --git a/pom.xml b/pom.xml index 0627f3f71..78672a8f2 100644 --- a/pom.xml +++ b/pom.xml @@ -450,25 +450,6 @@ - - com.spotify.fmt - fmt-maven-plugin - 2.27 - - - com.google.googlejavaformat - google-java-format - 1.27.0 - - - - - - format - - - - org.jacoco jacoco-maven-plugin