Mittwoch, 24. August 2022

Getting the google-java-format plugin to run in Eclipse with JDK >= 16

The google-java-style plugin can be found here. You can download the newest version in their release folder. Installation is pretty straight forward - just copy it into the dropins folder of your Eclipse installation folder.

but if you are running on a JDK with a version >= 16 it simply will not work. Going through the release history of the plugin you'll find a comment for version 1.10.0. If you are running the Java formatter, you'll hhave to add some VM args, when you start your Java application.

In order to get this working with your whole Eclipse IDE you'll have to edit the eclipse.ini in the following way. Took me a little bit, because I forgot the equals after the add-exports:

-vmargs

-Dosgi.requiredJavaVersion=11
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-Dsun.java.command=Eclipse
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
-Xms256m
-Xmx2048m
--add-modules=ALL-SYSTEM
--add-exports=jdk.compiler/com.sun.tools.javac.api=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

The first part might differ. The important lines are the --add-exports.