Question

Can anyone explain why I would be getting a different ordering of the output between tree and build-classpath on maven-dependency-plugin?

I'm running

mvn -pl releases org.apache.maven.plugins:maven-dependency-plugin:2.6:tree -Dtokens=whitespace -outputFile=tree.txt -DexcludeTransitive=true

On the command line to generate the output. The output from tree reflects the ordering defined in the pom file whereas the output from build-classpath does not.

Output from Tree http://pastebin.com/J2Q6iTK6

Output from build-classpath http://pastebin.com/k2SdrHP7

Any insight would be greatly appreciated.

Maven config

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>generate-classpath-windows</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>build-classpath</goal>
                    </goals>
                    <configuration>
                        <pathSeparator>,</pathSeparator>
                        <prefix>..\jars</prefix>
                        <fileSeparator>\</fileSeparator>
                        <outputFile>${project.build.directory}/deployment/bin/classpath.windows</outputFile>
                    </configuration>
                </execution>
                <execution>
                    <id>generate-classpath-unix</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>build-classpath</goal>
                    </goals>
                    <configuration>
                        <pathSeparator>:</pathSeparator>
                        <prefix>../jars</prefix>
                        <fileSeparator>/</fileSeparator>
                        <outputFile>${project.build.directory}/deployment/bin/classpath.unix</outputFile>
                    </configuration>
                </execution>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/deployment/jars</outputDirectory>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <excludeTransitive>true</excludeTransitive>
                <includeScope>runtime</includeScope>
                <regenerateFile>true</regenerateFile>
            </configuration>
        </plugin>

Info

Apache Maven 3.0.4 (r1232337; 2012-01-17 08:44:56+0000)
Maven home: C:\apps\apache-maven-3.0.4
Java version: 1.6.0_37, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_37\jre
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Was it helpful?

Solution

Classpaths are a linear representation, trees are nested. Maven should be trying to keep the root level dependencies first in the classpath as they are closest so should be resolved first.

From your output though this looks odd alright, I am not seeing what I would expect as normal logic re-classpath construction.

Additionally up until the 2.6 release of the dependency plugin, on Maven 3.x the dependency:tree output was incorrect. I wonder if there is a bug in build-classpath from the same root cause. I would ping this question to users@maven.apache.org to see if anyone (Hervé who fixed dependency:tree) knows the answer...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top