-
-
Notifications
You must be signed in to change notification settings - Fork 184
Recommended configuration
Maven users can add this plugin with the following addition to their pom.xml file. This will make sure that you pom file is sorted every time you compile the project.
...
<build>
<plugins>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>sort</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
The plugin comes with many parameters and this is how I would configure the plugin in a new project. It will still sort the pom-file each time your project is compiled.
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
...
</properties>
...
<build>
<plugins>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<predefinedSortOrder>custom_1</predefinedSortOrder>
<lineSeparator>\n</lineSeparator>
<encoding>${project.build.sourceEncoding}</encoding>
<sortProperties>true</sortProperties>
<sortDependencies>scope</sortDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>sort</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
What will it do?
- Keep your pom-file sorted every time you compile with maven
- Use a predefined sort order which I prefer myself (parent, basic info and properties on top; dependencies and plugins in the middle; other info and profiles last)
- Use unix-like line endings in the pom-file
- Use the explicit encoding UTF-8
- Sort the pom properties
- Keep blank lines (but not indent them)
- Sort dependencies by scope (to gather test dependencies together)
A more detailed description of the parameters. SortPom can also be configured for Build Servers.
If you want to run the SortPom plugin from commandline, it will be more convenient if you add a Plugin group to your general Maven Settings. To do this, open up ~/.m2/settings.xml and add the following plugin group:
<settings>
...
<pluginGroups>
<pluginGroup>com.github.ekryd.sortpom</pluginGroup>
</pluginGroups>
...
</settings>
You can then omit the full specification for the plugin and run
-
mvn sortpom:sort
-
mvn sortpom:verify