Utkarsh Saraf
Utkarsh Saraf

Reputation: 495

Plugin section in Maven for dependency tree

I am trying to print dependency tree as per dependency:tree for multimodule Maven project and firing the command

mvn org.apache.maven.plugins:maven-dependency-plugin:3.2.0:tree

works perfectly in this case.

For mentioning additional configurations such as creating aggregate dependency graph and writing to external directory, I made following changes in pom.xml.

<profile>
      <id>java-src</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
---
---
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
              <execution>
                <id>copy-dependencies</id>
                <phase>compile</phase>
                <goals>
                  <goal>tree</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
---
---
 </plugins>
      </build>
    </profile>

On running mvn tree, it is not working as expected and gives following error:

[ERROR] Unknown lifecycle phase "tree". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

Kindly help regarding the same.

Upvotes: 0

Views: 1386

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35853

There are two problems with this:

  1. As tgdavies already tried to point out, you need to call mvn dependency:tree.
  2. You defined the configuration in an execution bound to the compile phase. This means that the usual build (like mvn clean package) will create the dependency tree, but the configuration is not directly usable from command line. While you can call such an execution from command line by using @-notation, it is more advisable to move the configuration out of the execution block so that it can be used by vanilla calls to mvn dependency:tree.

Upvotes: 2

Related Questions