M1 Tip #5: Listing Dependencies

There are cases when you wish to list all your multiproject dependencies. To do that you can call the multiproject:projects-init goal from the Multi-Project plugin. Internally this goal uses the maven:reactor to gather the list of dependencies (there's a collectOnly attribute to tell the reactor not to execute any goal and only collect the list of dependencies).

Here's an example that prints the list of dependencies in an XML file:

<goal name="generateDependencies" 
    prereqs="multiproject:projects-init">
  <ant:mkdir dir="${maven.build.dir}"/>
  <maven:get var="multiprojects" 
      plugin="maven-multiproject-plugin" 
      property="multiprojects"/>
  <j:file name="${maven.build.dir}/projects.xml"
      prettyPrint="true" xmlns="projects">
    <projects>
      <j:forEach var="project" 
          items="${multiprojects}">
        <x:element name="project">
          <x:attribute name="name">
            ${project.name}</x:attribute>          
          <x:attribute name="artifactId">
            ${project.artifactId}</x:attribute>          
        </x:element>        
      </j:forEach>
    </projects>
  </j:file>
</goal>