Search code examples
mavengo-cd

How can I get a list of GAVs a maven package command will produce?


I'm looking for a (supported) mvn based command, which will give me a list of all the GroupID:ArtifactID:Version (GAV) for all artifacts that running a mvn package command would produce.

For a single module Maven project, with no parent pom, this is trivial: you can look inside the pom.

For a single module Maven project, with a parent pom, you could use help:effective-pom and it will present a pom file with the <version> element present.

For a multi module Maven project (reactor), you could actually do the same (didn't think so, learned so just now by trying it out). This will allow parsing the file for (multiple) <project> elements.

Anything else to consider?

The overall goal of this, is to be able to feed a downstream Continuous Delivery (http://go.cd/) stage/step/job with information on what version of it's upstream dependencies should be used.


Solution

  • In general you can't produce a list before the build has run...The problem is that based on the pom model not all artifacts are described, cause some plugins can produce supplemental artifacts (maven-assembly-plugin, maven-shade-plugin, maven-jar-plugin via test-jar etc.)

    What you can make is to get a list of produced artifacts after a build has run..(installed). The question of yours inspired me to implement an EventSpy which produces such list at the end of the build...which looks like this:

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.423 s
    [INFO] Finished at: 2016-05-08T13:22:10+02:00
    [INFO] Final Memory: 24M/310M
    [INFO] ------------------------------------------------------------------------
    [INFO] --             Maven Artifact Collector Summary                       --
    [INFO] ------------------------------------------------------------------------
    [INFO] test.maven.plugin.profiler:parse-pom:0.1.0-SNAPSHOT:jar
    [INFO] test.maven.plugin.profiler:parse-pom:0.1.0-SNAPSHOT:pom
    [INFO] test.maven.plugin.profiler:parse-pom:0.1.0-SNAPSHOT:jar:jar-with-dependencies
    

    What i can do is to enhance that and write a file which contains the information (in more or less any format)...At the moment it's just a PoC...May be you can give some more information or create issues or PR's and request what might be needed...may be this is also interesting for others...

    Furthermore your downstream part must have those artifacts within a repository cache available (either on a file system or via a repository manager or docker data container)...