diff --git a/src/it/projects/build-classpath-sorted/invoker.properties b/src/it/projects/build-classpath-sorted/invoker.properties
new file mode 100644
index 0000000000..68eb44ce27
--- /dev/null
+++ b/src/it/projects/build-classpath-sorted/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:build-classpath
diff --git a/src/it/projects/build-classpath-sorted/pom.xml b/src/it/projects/build-classpath-sorted/pom.xml
new file mode 100644
index 0000000000..a38aa8f28b
--- /dev/null
+++ b/src/it/projects/build-classpath-sorted/pom.xml
@@ -0,0 +1,68 @@
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.dependency
+ build-classpath-sorted
+ 1.0-SNAPSHOT
+
+ Test
+
+ Test dependency:build-classpath -Dmdep.sortClasspath=true
+
+
+
+ UTF-8
+
+
+
+
+ org.apache.maven
+ maven-profile
+ 2.0.6
+
+
+
+ classworlds
+ classworlds
+
+
+
+
+
+
+ org.apache.maven
+ maven-project
+ 2.0.6
+ sources
+
+
+ *
+ *
+
+
+
+
+
+
diff --git a/src/it/projects/build-classpath-sorted/test.properties b/src/it/projects/build-classpath-sorted/test.properties
new file mode 100644
index 0000000000..0c6ff4881b
--- /dev/null
+++ b/src/it/projects/build-classpath-sorted/test.properties
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+mdep.outputFile = target/classpath.txt
+mdep.fileSeparator = /
+mdep.pathSeparator = :
+mdep.prefix = PREFIX
+mdep.sortClasspath = true
diff --git a/src/it/projects/build-classpath-sorted/verify.bsh b/src/it/projects/build-classpath-sorted/verify.bsh
new file mode 100644
index 0000000000..9bc6c8f88b
--- /dev/null
+++ b/src/it/projects/build-classpath-sorted/verify.bsh
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+String classpath = StringUtils.replace( FileUtils.fileRead( new File( basedir, "target/classpath.txt" ) ), "PREFIX/", "" );
+String expected = "junit-3.8.1.jar:maven-model-2.0.6.jar:maven-profile-2.0.6.jar:maven-project-2.0.6-sources.jar:plexus-container-default-1.0-alpha-9-stable-1.jar:plexus-utils-1.4.1.jar";
+
+if ( !classpath.equals( expected ) )
+{
+ throw new Exception( "Unexpected classpath: '" + classpath + "'" );
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
index 4a4176a910..257a52aacd 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
@@ -68,6 +68,12 @@ public class BuildClasspathMojo
@Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
private String outputEncoding;
+ /**
+ * Should the classpath be lexicographically sorted.
+ */
+ @Parameter( property = "mdep.sortClasspath", defaultValue = "false" )
+ private boolean sortClasspath = false;
+
/**
* Strip artifact version during copy (only works if prefix is set)
*/
@@ -197,6 +203,10 @@ protected void doExecute()
}
List artList = new ArrayList<>( artifacts );
+ if ( sortClasspath )
+ {
+ artList.sort( this );
+ }
StringBuilder sb = new StringBuilder();
Iterator i = artList.iterator();