A collection of opinionated code formatting configurations for Java development tools.
Current release 1.1.0
java-code-style.xml: Eclipse formatter configuration file with themodern-javaprofile.
- Spotless: A code formatting plugin for Gradle and Maven.
- Eclipse: An integrated development environment widely used for Java development.
- IntelliJ IDEA: A popular Java IDE with built-in code formatting capabilities.
See below for installation instructions.
# Download the Eclipse formatter configuration
curl -o java-code-style.xml \
https://raw.githubusercontent.com/raduking/code-format/refs/heads/master/src/main/resources/java-code-style.xmlThis file can be imported directly into Eclipse or IntelliJ IDEA.
Eclipse:
- Go to
Settings>Java>Code Style>Formatter. - Click
Import...and select the downloadedjava-code-style.xmlfile. - Select the imported profile:
modern-java. - Optionally, set it as the default formatter.
- Apply the changes.
IntelliJ IDEA:
- Go to
Settings>Editor>Code Style>Java. - Click on the gear icon and select
Import Scheme>Eclipse XML Profile. - Select the downloaded
java-code-style.xmlfile. - Select the imported scheme
modern-java. - Apply the changes.
<dependency>
<groupId>io.github.raduking</groupId>
<artifactId>code-format</artifactId>
<version>1.1.0</version>
</dependency><properties>
<spotless.maven.plugin.version>3.10.4</spotless.maven.plugin.version>
<org.eclipse.jdt.core.version>3.47.0</org.eclipse.jdt.core.version>
<eclipse.formatter.version>4.38</eclipse.formatter.version>
<code.format.version>1.1.0</code.format.version>
</properties>
<plugins>
<!-- ... other plugins ... -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.maven.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>${org.eclipse.jdt.core.version}</version>
</dependency>
<dependency>
<groupId>io.github.raduking</groupId>
<artifactId>code-format</artifactId>
<version>${code.format.version}</version>
</dependency>
</dependencies>
<configuration>
<java>
<eclipse>
<file>java-code-style.xml</file>
<version>${eclipse.formatter.version}</version>
</eclipse>
<removeUnusedImports/>
<trimTrailingWhitespace/>
</java>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>