Skip to content

Latest commit

 

History

History
85 lines (62 loc) · 2.54 KB

README.md

File metadata and controls

85 lines (62 loc) · 2.54 KB

Build Status Maven Central

Dump Maven model as JSON

A Maven lifecycle extension that dumps the Maven model as JSON.

It is intended to quickly retrieve the list of all artifacts.

Usage

Preferred way is to add a profile to your top-level pom like this:

  <profiles>
    <profile>
      <id>dump-model</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.caffinitas.dump-maven-model</groupId>
            <artifactId>dump-maven-model</artifactId>
            <version>0.1.0</version>
            <extensions>true</extensions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

And run the following to get the dump the whole Maven model as JSON.

mvn -Pdump-model validate -q > model.json

Option: restrict to root project

Setting the property dump-model.all-projects to false restricts the output to the root project.

Example:

mvn -Ddump-model.all-projects=false -Pdump-model validate -q > model.json

JSON model

The JSON model currently contains two top-level properties:

  • model mirroring (most of) the Maven model including all modules. Property names are the same as in the Maven model classes (org.apache.maven.model.Model and related), but not all available properties are mapped.
  • allModelArtifacts list containing all artifacts that the Maven model contains, including the artifact of the top-level module and all submodules.

Example: Dump the IDs of all modules in your multimodule project

jq -r '.allModelArtifacts[].id' < model.json

Example: Dump the artifact IDs of all modules in your multimodule project

jq -r '.allModelArtifacts[].artifactId' < model.json

As above, but prefixed with :.

jq -r '":" + .allModelArtifacts[].artifactId' < model.json

As above, but a single, comma-separated list.

jq -r '[":" + .allModelArtifacts[].artifactId] | join(",")' < model.json

Slow Alternative

You could also the exec-maven-plugin, however this will take quite a while.

man -q org.codehaus.mojo:exec-maven-plugin:1.6.0:exec@noid -Dexec.executable=echo -Dexec.args='${project.groupId}:${project.artifactId}:${project.version}:${project.packaging}'