Skip to content

Instantly share code, notes, and snippets.

Created August 12, 2019 04:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generate a basic parent POM from all subfolders that contain Maven projects.
#!/usr/bin/env python3
import os
import argparse
parser = argparse.ArgumentParser(description='Generate a Maven parent pom for existing Maven projects in a folder.')
parser.add_argument('root', default='.', nargs='?',
help='root (parent) folder')
parser.add_argument('--group', default='localhost',
help='groupId for parent POM')
parser.add_argument('--artifact', default='parent',
help='artifactId for parent POM')
parser.add_argument('--version', default='0.0.1-SNAPSHOT',
help='version for parent POM')
args = parser.parse_args()
# quick hack without using an xml lib
pom = "<project>\n" \
" <modelVersion>4.0.0</modelVersion>\n" \
f" <groupId>{}</groupId>\n" \
f" <artifactId>{args.artifact}</artifactId>\n" \
f" <version>{args.version}</version>\n" \
" <packaging>pom</packaging>\n" \
" <modules>\n"
# scan the subdirs and consider all those that contain a pom.xml
for entry in sorted(os.scandir(args.root), key=lambda e :
if entry.is_dir() and os.path.isfile(os.path.join(entry.path, 'pom.xml')):
pom += f" <module>{}</module>\n"
pom += " </modules>\n" \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment