如何列出Maven项目中的活动子模块? [英] How to list active sub-modules in a Maven project?

查看:79
本文介绍了如何列出Maven项目中的活动子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的项目,其中有许多包含POM文件的目录,但是其中只有一些是特定父项目的子模块(可能是传递的).

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.

很明显,Maven知道相关文件的列表,因为它解析所有<module>标记以查找它们.但是,我只在[INFO]注释中看到<name>的列表,而不是这些模块的路径.

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.

有没有办法让Maven输出所有POM文件的列表,这些文件提供对作为给定项目的反应堆构建的一部分的项目的引用?

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?

推荐答案

这是在Maven以外的Linux上使用strace进行此操作的一种方法.

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 

第一行在strace下运行mvn dependency:tree,要求strace在任何派生之后将对open(2)系统调用的所有调用输出到文件opens.txt(因为Java是线程化的).该文件如下所示:

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

第二行要求Perl在引号内输出恰好以pom.xml结尾的任何文本. (-l标志处理打印换行符,-n将代码单引号包装在一个循环中,该循环仅读取命令行上的任何文件,而-e处理脚本本身,该脚本使用正则表达式查找对打开.)

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

这篇关于如何列出Maven项目中的活动子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆