Usage

The Eclipse Format Plugin is used to format java source files following coding convention configured with the Eclipse IDE.

This plugin will format all java source files in the sourceDirectory and, if specified, the testDirectory following the configured coding convention.

If no configuration file is specified, the default format file will be used.

Configuration

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>net.sf.maven.plugins</groupId>
        <artifactId>maven-eclipse-format</artifactId>
        <version>1.0</version>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

Using Your Own Eclipse Configuration File

You can use a custom configuration file placed in a directory of your liking. Exporting the code format rules can be done as follows:

  • In Eclipse, go to Window > Preferences > Java > Code Style > Formatter
  • Click on the Edit button of the profile you like to export
  • Click the Export button.

    Please note that build-in format profiles cannot be exported in Eclipse. You need to make your own profile, based on one of the build-in profiles, and export that one.

    For this example we want to use the file src/config/sun-format-standards.xml. This is how you would configure that.

    <project>
      ...
      <build>
        ...
        <plugins>
          <plugin>
            <groupId>net.sf.maven.plugins</groupId>
            <artifactId>maven-eclipse-format</artifactId>
            <version>1.0</version>
            <configuration>
              <formatConfig>${basedir}/src/config/sun-format-standards.xml</formatConfig>
            </configuration>
          </plugin>
        </plugins>
        ...
      </build>
      ...
    </project>

    For all available configuration options see this page.

How To Run The Format Plugin

mvn eclipse-format:format