• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Maven | Maven Dependency Plugin
  1. Maven Dependency Plugin
  2. The help goal
  3. Example: Using dependency plugin

  1. Maven Dependency Plugin
    The Maven Dependency Plugin provides utility goals to manage and work with dependencies, including copying, unpacking, analyzing, and resolving dependencies.

    Plugin coordinates:
    • Group Id: org.apache.maven.plugins
    • Artifact Id: maven-dependency-plugin
    • Version: 3.8.1

    Plugin Prefix: dependency

    The dependency plugin provides the following goals:
    • help: Displays help information about the maven-dependency-plugin. Use mvn dependency:help -Ddetail=true -Dgoal=<goal-name> to display parameter details for specific goals.

    • analyze: Analyzes project dependencies and categorizes them as: used and declared, used and undeclared, or unused and declared. This helps identify dependency issues in your project.

    • analyze-dep-mgt: Examines dependencies after resolution and identifies mismatches in the <dependencyManagement> section.

    • analyze-duplicate: Identifies duplicate dependencies declared in the <dependencies/> and <dependencyManagement/> sections of the pom.xml.

    • analyze-only: Performs the same analysis as the analyze goal but does not fail the build based on the results.

    • analyze-report: Generates a report summarizing dependency analysis results, showing used/declared, used/undeclared, and unused/declared dependencies.

    • resolve: Resolves project dependencies from the repository and downloads them to the local repository.

    • resolve-plugins: Resolves all project plugins, reports, and their dependencies.

    • tree: Displays the dependency tree for the project, showing all dependencies and their transitive dependencies in a hierarchical format.

    • list: Displays a list of all dependencies for the project.

    • list-classes: Retrieves a specified artifact from remote repositories and lists all classes contained within it.

    • list-repositories: Lists all repositories used by the build and by transitive dependencies after resolving all project dependencies.

    • display-ancestors: Displays all ancestor POMs of the current project.

    • sources: Resolves and downloads source artifacts for project dependencies from the repository.

    • copy: Copies specified artifacts from the repository to defined locations on the file system.

    • copy-dependencies: Copies all project dependencies from the repository to a specified location.

    • collect: Collects project dependencies from the repository. This goal is primarily used internally by Maven.

    • unpack: Retrieves specified artifacts from the repository and unpacks them to a defined location.

    • unpack-dependencies: Unpacks all project dependencies from the repository to a specified location.

    • purge-local-repository: Removes project dependencies from the local repository and optionally re-resolves them.

    • build-classpath: Generates a classpath string containing dependencies from the local repository and outputs it to a file or log.

    • get: Resolves a single artifact, including its transitive dependencies if specified, from remote repositories.

    • go-offline: Resolves all project dependencies, plugins, and reports along with their dependencies to prepare for offline usage.

    • properties: Creates a property for each project dependency that points to the artifact's file location.

    Common usage examples of the maven-dependency-plugin:
    $ mvn dependency:analyze
    $ mvn dependency:resolve
    $ mvn dependency:tree
    $ mvn dependency:purge-local-repository
  2. The help goal
    The help goal provides general information about the dependency plugin, including available goals and their parameters.

    Use the detail parameter to get detailed information about all goals and their configuration options:
    # Display basic plugin information
    $ mvn dependency:help
    
    # Display detailed information about all goals and parameters
    $ mvn dependency:help -Ddetail=true
    If you need to use the plugin's full coordinates instead of its prefix, you can do that as follows:
    # Display basic plugin information
    $ mvn org.apache.maven.plugins:maven-dependency-plugin:3.8.1:help
    
    # Display detailed information about all goals and parameters
    $ mvn org.apache.maven.plugins:maven-dependency-plugin:3.8.1:help -Ddetail=true
    You can also use the Maven help plugin to describe the dependency plugin:
    # Basic plugin description using help plugin
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-dependency-plugin:3.8.1"
    
    # Detailed plugin description with all parameters
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-dependency-plugin:3.8.1" -Ddetail=true
    To get specific information about a goal, use the goal parameter:
    # Help for the 'analyze' goal
    $ mvn org.apache.maven.plugins:maven-dependency-plugin:3.8.1:help -Dgoal=analyze -Ddetail=true
    
    # Help for the 'analyze' goal using the help plugin
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-dependency-plugin:3.8.1" -Dgoal=analyze -Ddetail=true
    Note: When using the plugin's help goal directly, you don't need to specify the version if the plugin is already configured in your POM or if you want to use the latest version.
  3. Example: Using dependency plugin
    This example shows how to configure the dependency plugin in your pom.xml file.

    The configuration includes two executions. The first execution runs dependency analysis during the package phase and is configured to fail the build if warnings are found. The second execution copies a specific artifact to the endorsed directory during the validate phase.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.8.1</version>
    
        <executions>
            <execution>
                <id>dependency-analyze</id>
                <phase>package</phase>
                <goals>
                    <goal>analyze</goal>
                </goals>
                <configuration>
                    <failOnWarning>true</failOnWarning>
                    <ignoreNonCompile>true</ignoreNonCompile>
                    <ignoredDependencies>true</ignoredDependencies>
                    <outputXML>true</outputXML>
    
                    <ignoredUnusedDeclaredDependencies>
                        <ignoredUnusedDeclaredDependency>commons-io:commons-io:jar:*</ignoredUnusedDeclaredDependency>
                    </ignoredUnusedDeclaredDependencies>
    
                    <ignoredUsedUndeclaredDependencies>
                        <ignoredUsedUndeclaredDependency>org.apache.httpcomponents:httpcore:jar:*</ignoredUsedUndeclaredDependency>
                    </ignoredUsedUndeclaredDependencies>
                </configuration>
            </execution>
    
            <execution>
                <phase>validate</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/endorsed</outputDirectory>
                    <silent>true</silent>
                    <artifactItems>
                        <artifactItem>
                            <groupId>javax</groupId>
                            <artifactId>javaee-endorsed-api</artifactId>
                            <version>6.0</version>
                            <type>jar</type>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
© 2025  mtitek