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.
The following script prints artifactId's of all sub-modules:
mvn -Dexec.executable='echo' -Dexec.args='${project.artifactId}' exec:exec -q
Example output:
build-tools aws-sdk-java-pom core annotations utils http-client-spi http-client-tests http-clients apache-client test-utils sdk-core ...