You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support Module Import Declarations (JEP 476, JDK 23) #1213
// this will import e.g. all the classes from package java.util, java.util.stream, java.io, java.lang, java.nio.fileimportmodulejava.base;
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
3.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 Kopp
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.
Activity
cushon commentedon Mar 23, 2025
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
sormuras commentedon Mar 26, 2025
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-statementssormuras commentedon Jul 15, 2025
Finalized as "JEP 511: Module Import Declarations" in Java 25.
cushon commentedon Jul 16, 2025
The 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.
Initial support for `import module` in google-java-format
Initial support for `import module` in google-java-format
Initial support for `import module` in google-java-format
cushon commentedon Oct 13, 2025
I 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#946sormuras commentedon Oct 13, 2025
Great news, Liam.
The guide will disallow them, but
gjfwill keep them? I.e.gjfwill not expand them to normal type imports?cushon commentedon Oct 13, 2025
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.