Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output a simple list of Maven dependencies

I'm trying to get a simple, machine-parsable list of dependencies from my POM. If I do:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:list -f sample.pom

I get a load of pointless [INFO] output:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - my-group:my-project:jar:1.0
[INFO]    task-segment: [org.apache.maven.plugins:maven-dependency-plugin:2.1:list]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:list {execution: default-cli}]
[INFO] 
[INFO] The following files have been resolved:
[INFO]    com.squareup.picasso:picasso:jar:2.5.2:compile
[INFO]    commons-io:commons-io:jar:1.3.2:compile
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Mon Jan 11 14:06:05 GMT 2016
[INFO] Final Memory: 17M/325M
[INFO] ------------------------------------------------------------

which I then have to manually scrape to get the info. If I add the -q switch

mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.1:list -f sample.pom

I get a download progress message or nothing if it's already local (unless there's an error of course).

Is there really no way to execute the dependency list command, so it just outputs a simple list of downloaded dependencies? Something like:

> mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:list -f sample.pom
    com.squareup.picasso:picasso:jar:2.5.2:compile
    commons-io:commons-io:jar:1.3.2:compile
> 
like image 652
adelphus Avatar asked Jan 07 '23 20:01

adelphus


1 Answers

It is possible to redirect the output of the maven-dependency-plugin to a file with the help of the outputFile attribute:

If specified, this parameter will cause the dependencies to be written to the path specified, instead of writing to the console.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:list -f sample.pom -DoutputFile="..."

The plugin will create the file if it does not exist. If it already exists, the content will be overwritten (but this can be controlled by the appendOutput attribute).

This should give you a simple and parsable list of dependencies.


As a side-note, I notice you are using a very old version of the maven-dependency-plugin (2.1 is dated January 2009). The latest is 2.10 at this time.

like image 50
Tunaki Avatar answered Jan 15 '23 05:01

Tunaki