How to list active sub-modules in a Maven project?

前端 未结 8 1292
长发绾君心
长发绾君心 2020-12-24 13:26

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.

8条回答
  •  情话喂你
    2020-12-24 13:52

    Here's a way to do this on Linux outside of Maven, by using strace.

    $ strace -o opens.txt -f -e open mvn dependency:tree > /dev/null
    $ perl -lne 'print $1 if /"(.*pom\.xml)"/' opens.txt 
    

    The first line runs mvn dependency:tree under strace, asking strace to output to the file opens.txt all the calls to the open(2) system call, following any forks (because Java is threaded). This file looks something like:

    9690  open("/etc/ld.so.cache", O_RDONLY) = 3
    9690  open("/lib/libncurses.so.5", O_RDONLY) = 3
    9690  open("/lib/libdl.so.2", O_RDONLY) = 3
    

    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 :-)

提交回复
热议问题