Repository navigation
Support Module Import Declarations (JEP 476, JDK 23) #1213
Description
Activity
Note that this is currently a preview feature, there's a draft JEP to finalize the feature in Java 25: https://openjdk.org/jeps/8344700
I wonder where GJF will put
import MODULE;declarations in relation to thestaticand non-staticblock as described in https://google.github.io/styleguide/javaguide.html#s3.3-import-statements3.3.3 Ordering and spacing
Imports are ordered as follows:- All static imports in a single block.
- All non-static imports in a single block.
If there are both static and non-static imports, a single blank line separates the two blocks. There are no other blank lines between import statements.
Reacted by Jonathan Bluett-Duncan, Sebastiaan Speck and Oliver KoppFinalized as "JEP 511: Module Import Declarations" in Java 25.
Reacted by Liam Miller-Cushon and Oliver KoppThe style guide update for module imports is still TBD, but that should happen in time for the Java 25 GA.
It's possible it will discourage module imports in favor of single-type imports (similar to how wildcard imports are already discouraged).
But either way, google-java-format should support the syntax for files that use it.
Reacted by Oliver KoppI pushed a release that adds support for
import module.The style guide will be updated to disallow
import module(similar to how wildcard imports are disallowed): google/styleguide#946Great news, Liam.
The guide will disallow them, but
gjfwill keep them? I.e.gjfwill not expand them to normal type imports?g-j-f will preserve them.
It doesn't have enough information to expand them even if we wanted to do that in the formatter. That might be something we'd add to Error Prone eventually, similar to https://errorprone.info/bugpattern/WildcardImport.
- marked Cannot format file when using import module (JEP 511) in JDK 25 #1278 as a duplicate of this issue
on Oct 28, 2025
Consider the following code:
When trying to use google-java-format 1.24.0, this results in:
com.google.googlejavaformat.java.FormatterException: 2:1: error: expected token: 'module'; generated java instead