Skip to content

Latest commit

 

History

History
117 lines (96 loc) · 4.22 KB

README.md

File metadata and controls

117 lines (96 loc) · 4.22 KB

Code Format

A collection of opinionated code formatting configurations for Java development tools.

Maven Central GitHub Release License Java PRs

Status

branch: master Build (master) branch: develop Build (develop)

Releases

Current release 1.1.0

Contents

  • java-code-style.xml: Eclipse formatter configuration file with the modern-java profile.

Supported Tools

  • 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.

Installation

Direct File Usage

# 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.xml

This file can be imported directly into Eclipse or IntelliJ IDEA.

Eclipse:

  1. Go to Settings > Java > Code Style > Formatter.
  2. Click Import... and select the downloaded java-code-style.xml file.
  3. Select the imported profile: modern-java.
  4. Optionally, set it as the default formatter.
  5. Apply the changes.

IntelliJ IDEA:

  1. Go to Settings > Editor > Code Style > Java.
  2. Click on the gear icon and select Import Scheme > Eclipse XML Profile.
  3. Select the downloaded java-code-style.xml file.
  4. Select the imported scheme modern-java.
  5. Apply the changes.

Maven

<dependency>
    <groupId>io.github.raduking</groupId>
    <artifactId>code-format</artifactId>
    <version>1.1.0</version>
</dependency>

Spotless Maven Plugin Configuration

<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>