I have a complex project where there are many directories that have POM files, but only some of which are sub-modules (possibly transitively) of a particular parent project.
Obviously, Maven knows the list of relevant files because it parses all the <module>
tags to find them. But, I only see a list of the <name>
s in the [INFO] comments, not the paths to those modules.
Is there a way to have Maven output a list of all the POM files that provided references to projects that are part of the reactor build for a given project?
This is quite simple but it only gets the artifactId, from the root (or parent) module:
If you want the directories
The following script prints artifactId's of all sub-modules:
mvn -Dexec.executable='echo' -Dexec.args='${project.artifactId}' exec:exec -q
Example output:
Here's a way to do this on Linux outside of Maven, by using strace.
The first line runs
mvn dependency:tree
under strace, asking strace to output to the fileopens.txt
all the calls to theopen(2)
system call, following any forks (because Java is threaded). This file looks something like:The second line asks Perl to print any text inside quotes that happens to end in pom.xml. (The
-l
flag handles printing newlines, the-n
wraps the code single quotes in a loop that simply reads any files on the command line, and the-e
handles the script itself which uses a regex to find interesting calls to open.)It'd be nice to have a maven-native way of doing this :-)
This is the command I use for listing all pom.xml files inside a project at the root of the project.
find -name pom.xml | grep -v target | sort
What the command do :
find -name pom.xml
what I searchgrep -v target
avoid to list pom.xml inside target/ directorysort
list the result in alphabetical orderI had the same problem but solved it without
strace
. Themvn exec:exec
plugin is used totouch pom.xml
in every project, and thenfind
the recently modifiedpom.xml
files:And you have your projects list in the
maven_projects_list.txt
file.