11

I'm facing a rather large multi module maven project. I would like to see how the root (parent) project is composed out of subprojects/ child projects in the form of groupId:artifactId (possible with some identation to reflect the hierarchy.

Of course I can write my own plugin to get this printout, but I reckon that there must be something available of the shelf.

artbristol
  • 32,010
  • 5
  • 70
  • 103
Sjaak
  • 3,602
  • 17
  • 29

3 Answers3

7

Hello late answer but I have added a plugin into maven repository:

<dependency>
    <groupId>org.qunix</groupId>
    <artifactId>structure-maven-plugin</artifactId>
    <version>0.0.1</version>
</dependency>

To run the plugin you will need to add into your pom as below:

<build>
        <plugins>

            <plugin>
                <groupId>org.qunix</groupId>
                <artifactId>structure-maven-plugin</artifactId>
                <version>0.0.1</version>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>
                                printModules
                            </goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>

then output will look like:

   [INFO] --- structure-maven-plugin:0.0.1:printModules (default) @ test ---
[INFO] 

Project structure (all modules):



                test
                |
                |__ a
                |
                |__ b
                |
                |
                \__ c
                    |
                    |__ d
                    |
                    |__ e
                    |
                    |__ f

If you want to print all files insted of modules use the goal: printAll or if you want just folders use the goal:printFolders. <inherited> means dont execute plugin also in modules and <ignore> mean skip this files using regex pattern.

EDIT: there is never version you can pull from github: https://github.com/buraksarac/MavenStructurePlugin

HRgiger
  • 2,750
  • 26
  • 37
  • 1
    This plugin is awesome! You're the best. – barbiepylon Oct 07 '16 at 16:15
  • @javajavajava I am glad it helped:) – HRgiger Oct 10 '16 at 08:25
  • 1
    @HRgiger great work! This is exactly what I wanted. Sorry for my (very) late reply. – Sjaak Feb 11 '17 at 12:06
  • Thank you for the plugin @HRgiger. However, I would be wary with using plugin as it has two major vulnerabilities. https://mvnrepository.com/artifact/org.qunix/structure-maven-plugin/0.0.2 Could you address them in 0.0.2? However, it seems 0.0.1 has no vulnerabilities. – dodobird Aug 24 '23 at 07:33
0

I haven't encounter such plugin so far nor even heard about one. Google doesn't know about it too, so it's likely you have to write own plugin or try to parse mvn dependency:tree or just reactor build order, probably using heavily console output streaming and so.

Michał Kalinowski
  • 16,925
  • 5
  • 35
  • 48
0

I think that mvn dependency:tree is way to go.

You should try this :

mvn dependency:tree -DoutputFile=target/dependencies.txt
cat target/dependencies.txt | awk -F ':' '{print $1":"$2}'

That way, you will have a nice dependency tree with indentation but without scope, version and type :)

Pierre Laporte
  • 1,205
  • 8
  • 11
  • Thanks. But I meant it in the opposite direction. Yes, you can print the dependencies of a sub component by means of tree. However, can you also collect all dependencies required by the root project (that is constituted of sub components)? – Sjaak Oct 03 '12 at 12:01