Manage dependencies with the Maven Dependency Plugin

April 4th, 2010 by

In a maven project there are lots of dependencies to handle – often one wants to know which version of a software comes from.

The solution to this problem is the Maven Dependency Plugin which helps you to find used/unused/declared/undeclared dependencies in your project.

In addition the plugin allows you to copy or unpack artifacts.

 

Maven Goals

  • dependency:copy – copies artifacts defined in the config to a specified location – details available here
  • dependency:resolve – resolves all dependencies and shows the versions
  • dependency:go-offline – resolves everything the project needs like dependencies, plugins and reports
  • dependency:analyze - parses the dependencies and shows if they are used/declared/unused/undeclared ..
  • dependency:analyze-dep-gmt - finds mismatches between resolved dependencies and those listed in the dependencyManagement section
  • dependency:tree – shows a nice dependency tree for the maven project

Examples

  • dependency:tree (old jsf-myfaces project skeleton)
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'dependency'.
    [INFO] ------------------------------------------------------------------------
    [INFO] Building hasCode.com - Faces Project
    [INFO]    task-segment: [dependency:tree]
    [INFO] ------------------------------------------------------------------------
    [INFO] [dependency:tree]
    [INFO] com.hascode.jsf:faces-test:war:0.0.1-SNAPSHOT
    [INFO] +- org.apache.myfaces.core:myfaces-api:jar:1.2.2:compile
    [INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
    [INFO] +- org.apache.myfaces.core:myfaces-impl:jar:1.2.2:compile
    [INFO] |  +- commons-collections:commons-collections:jar:3.2:compile
    [INFO] |  +- commons-discovery:commons-discovery:jar:0.4:compile
    [INFO] |  +- commons-codec:commons-codec:jar:1.3:compile
    [INFO] |  +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
    [INFO] |  \- commons-digester:commons-digester:jar:1.8:compile
    [INFO] +- org.apache.myfaces.tomahawk:tomahawk:jar:1.1.6:runtime
    [INFO] |  +- commons-validator:commons-validator:jar:1.3.1:runtime
    [INFO] |  +- commons-fileupload:commons-fileupload:jar:1.0:runtime
    [INFO] |  +- commons-el:commons-el:jar:1.0:runtime
    [INFO] |  +- oro:oro:jar:2.0.8:runtime
    [INFO] |  \- commons-lang:commons-lang:jar:2.1:runtime
    [INFO] +- jstl:jstl:jar:1.2:runtime
    [INFO] +- com.sun.facelets:jsf-facelets:jar:1.1.11:compile
    [INFO] \- junit:junit:jar:4.0:test
    [INFO] ------------------------------------------------------------------------
  • dependency:analyze-dep-mgt
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'dependency'.
    [INFO] ------------------------------------------------------------------------
    [INFO] Building hasCode.com - Faces Project
    [INFO]    task-segment: [dependency:analyze-dep-mgt]
    [INFO] ------------------------------------------------------------------------
    [INFO] [dependency:analyze-dep-mgt]
    [INFO] Found Resolved Dependency / DependencyManagement mismatches:
    [INFO]    Nothing in DepMgt.
    [INFO] ------------------------------------------------------------------------
  • dependency:resolve
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'dependency'.
    [INFO] ------------------------------------------------------------------------
    [INFO] Building A custom project using myfaces
    [INFO]    task-segment: [dependency:resolve]
    [INFO] ------------------------------------------------------------------------
    [INFO] [dependency:resolve]
    [INFO]
    [INFO] The following files have been resolved:
    [INFO]    com.sun.facelets:jsf-facelets:jar:1.1.11:compile
    [INFO]    commons-beanutils:commons-beanutils:jar:1.7.0:compile
    [INFO]    commons-codec:commons-codec:jar:1.3:compile
    [INFO]    commons-collections:commons-collections:jar:3.2:compile
    [INFO]    commons-digester:commons-digester:jar:1.8:compile
    [INFO]    commons-discovery:commons-discovery:jar:0.4:compile
    [INFO]    commons-el:commons-el:jar:1.0:runtime
    [INFO]    commons-fileupload:commons-fileupload:jar:1.0:runtime
    [INFO]    commons-lang:commons-lang:jar:2.1:runtime
    [INFO]    commons-logging:commons-logging:jar:1.1.1:compile
    [INFO]    commons-validator:commons-validator:jar:1.3.1:runtime
    [INFO]    jstl:jstl:jar:1.2:runtime
    [INFO]    junit:junit:jar:4.0:test
    [INFO]    org.apache.myfaces.core:myfaces-api:jar:1.2.2:compile
    [INFO]    org.apache.myfaces.core:myfaces-impl:jar:1.2.2:compile
    [INFO]    org.apache.myfaces.tomahawk:tomahawk:jar:1.1.6:runtime
    [INFO]    oro:oro:jar:2.0.8:runtime
    [INFO]
    [INFO] ------------------------------------------------------------------------

Resources

Article Updates

  • 2015-03-03: Table of contents added.

    Tags: , ,

    Leave a Reply

    Please note, that no personal information like your IP address is stored and you're not required to enter you real name.

    Comments must be approved before they are published, so please be patient after having posted a comment - it might take a short while.

    Please leave these two fields as-is:
    Search
    Categories