From d1e9c9e6f8b29f9631fbd690ab29e4030049e044 Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Thu, 12 Dec 2024 19:27:53 +0000 Subject: [PATCH] ICU-22921 Document a way to remove unused includes from command line --- docs/processes/release/tasks/healthy-code.md | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/processes/release/tasks/healthy-code.md b/docs/processes/release/tasks/healthy-code.md index 5d4aa295faf2..f1e7bf6a7bf2 100644 --- a/docs/processes/release/tasks/healthy-code.md +++ b/docs/processes/release/tasks/healthy-code.md @@ -126,6 +126,37 @@ the UTF-8 signature byte sequence ("BOM").~~ ## Clean up import statements +### From command line + +This can be done from command line using the +[Google Java Format](https://github.com/google/google-java-format) tool. + +**WARNING:** requires JDK 17 or newer (December 2024) + +Download the latest Google Java Format from Maven Central: +```sh +mvn dependency:copy -Dartifact=com.google.googlejavaformat:google-java-format:LATEST:jar:all-deps \ + -DoutputDirectory=/tmp \ + -Dmdep.stripVersion=true \ + -q -ntp +``` + +Cleanup all Java files (only imports, nothing else): +```sh +find . -type f -name '*.java' | xargs java -jar /tmp/google-java-format-all-deps.jar -i --aosp --fix-imports-only --skip-sorting-imports +``` + +Remove the Google Java Format artifact from the temporary folder: +```sh +rm /tmp/google-java-format-all-deps.jar +``` + +You can (of course) download it from +[GitHub Releases](https://github.com/google/google-java-format/releases). \ +Or save it in a personal tools folder and keep it around. + +### From Eclipse + The Eclipse IDE provides a feature which allow you to organize import statements for multiple files. Right click on projects/source folders/files, you can select \[Source\] - \[Organize Imports\] which resolve all wildcard imports and sort