This subproject packages the google formatter into an Eclipse plugin.
Additionally, the plugin provides two options to control the formatting behavior.
- Organize imports
When selected, the plugin reorders the imports by using google-java-format. It is recommended to add a Save Action so that the code will be formatted automatically when saving. Make sure, that theOrganize importsoption is unchecked. - Remove unused imports
When selected, the plugin also removes unused imports.
Enabling
google-java-format Eclipse plugin can be downloaded from the releases page. Drop it into the Eclipse drop-ins folder to activate the plugin.
The plugin adds a google-java-format formatter implementation that can be configured in Window > Preferences > Java > Code Style > Formatter > Formatter Implementation.
If the plugin is not recognized correctly, it may help to
- switch to default Eclipse formatter in preferences
- close Eclipse
- delete
google-java-format-eclipse-plugin-x.x.x.jarfrom dropins folder - start Eclipse using the
--cleanoption - close Eclipse again
- drop
google-java-format-eclipse-plugin-x.x.x.jarinto dropins folder - start Eclipse using the
--cleanoption
Development
The plugin can either be built directly with Eclipse Tycho or exported from the Eclipse plugin project. Both approaches were tested with Linux only.
Before you can open the plugin project within Eclipse or build the plugin with Tycho, the necessary libraries must be copied.
Copy dependencies
Make sure Apache Maven is installed and the binary can run
Make sure that at least a JDK 11 (e.g. AdoptOpenJDK) is installed and configured in the environment variable JAVA_HOME.
From the base directory execute
to build current google-java-formatter and copy the libraries to the Eclipse subproject.
Building plugin using Tycho
After copying the necessary libraries, execute from the base directory
$ cd ./eclipse_project
$ mvn clean install
The created plugin google-java-format-eclipse-plugin-x.x.x.jar is placed in the eclipse_plugin/target directory.
Building plugin using Eclipse
As an alternative to building with Tycho, the plugin can be exported directly from the Eclipse Plugin Project.. Open the eclipse_plugin project in a recent Eclipse SDK build. From File > Export select Plugin-in Development > Deployable plugin-ins and fragments and follow the wizard to export a plugin jar.
This was tested with Eclipse Version 2021-09 (4.21.0).