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

2020-02-23 07:17发布

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?

标签: maven-2
8条回答
The star\"
2楼-- · 2020-02-23 07:49

The solution I found is quite simple:

mvn -B -f "$pom_file" org.codehaus.mojo:exec-maven-plugin:1.4.0:exec \
    -Dexec.executable=/usr/bin/echo \
    -Dexec.args='${basedir}/pom.xml'| \
    grep -v '\['

This is a little bit tricky due to the need to grep out the [INFO|WARNING|ERROR] lines and make it usable for scripting but saved me a lot of time since you can put any expression there.

查看更多
Fickle 薄情
3楼-- · 2020-02-23 07:51

I don't have a direct answer to the question. But using some kind of "module path" as naming convention for the <name> of my modules works for me. As you'll see, this convention is self explaining.

Given the following project structure:

.
├── pom
│   ├── pom.xml
│   └── release.properties
├── pom.xml
├── samples
│   ├── ejb-cargo-sample
│   │   ├── functests
│   │   │   ├── pom.xml
│   │   │   └── src
│   │   ├── pom.xml
│   │   └── services
│   │       ├── pom.xml
│   │       └── src
│   └── pom.xml
└── tools
    ├── pom.xml
    └── verification-resources
        ├── pom.xml
        └── src

Here is the output of a reactor build:

$ mvn compile
[INFO] Scanning for projects...
[INFO] Reactor build order: 
[INFO]   Personal Sandbox - Samples - Parent POM
[INFO]   Personal Sandbox - Samples - EJB3 and Cargo Sample
[INFO]   Personal Sandbox - Tools - Parent POM
[INFO]   Personal Sandbox - Tools - Shared Verification Resources
[INFO]   Personal Sandbox - Samples - EJB3 and Cargo Sample - Services
[INFO]   Personal Sandbox - Samples - EJB3 and Cargo Sample - Functests
[INFO]   Sandbox Externals POM
...

This gives IMHO a very decent overview of what is happening, scales correctly, and it's pretty easy to find any module in the file system in case of problems.

Not sure this does answer all your needs though.

查看更多
登录 后发表回答