-
-
Notifications
You must be signed in to change notification settings - Fork 184
SortDependencies
The dependencies in a pom file can be sorted alphabetically and the parameter sortDependencies decides how it should do that.
Example:
sortDependencies=groupId,artifactId
will sort the dependencies first by groupId and then by artifactId (if the groupId is the same).
The argument list is the same as the child element names of the dependency element, i.e. groupId
, scope
, and artifactId
. The list is separated by ; : or , and it is not recommended to contain space.
The value none
can be used to omit sorting altogether. This is useful if normal dependencies are sorted by parameter sortDependencies
and dependency management shouldn't be sorted at all by setting <sortDependencyManagement>none</sortDependencyManagement>
.
If scope is specified in the list, then scope is not sorted alphabetically. It has the following sort order: IMPORT, COMPILE (or empty), PROVIDED, SYSTEM, RUNTIME and TEST. The default sorting was changed to set IMPORT first in SortPom version 3.0.0.
The plugin does not know anything about Maven infrastructure, so if dependency management is used, it can ruin the sorting.
Example:
Dependency management has been used to specify scope for the most common dependencies and some dependencies do not have scope specified.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
If the plugin has the parameter sortDependencies=scope then the junit dependency will be sorted before hamcrest because it is treated as having no scope (default: compile scope). The plugin does not know that the scope is provided by dependency management.
The recommended solution to this is to omit scope in dependency management.
Earlier versions of the plugin had a boolean argument:
true means 'groupId,artifactId'
false means empty list.
This is not allowed at all since SortPom version 3.0.0.
Please use this option with caution. Maven reads dependencies according to the order in the pom-file when compiling. Rearranging the order may affect the compilation output.