Created
August 12, 2019 04:43
-
-
Save klausbrunner/cd437317ca0dd50ca2c0374b0a155f9e to your computer and use it in GitHub Desktop.
Generate a basic parent POM from all subfolders that contain Maven projects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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>{args.group}</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 : e.name): | |
if entry.is_dir() and os.path.isfile(os.path.join(entry.path, 'pom.xml')): | |
pom += f" <module>{entry.name}</module>\n" | |
pom += " </modules>\n" \ | |
"</project>\n" | |
print(pom) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment