Created
July 5, 2018 17:58
-
-
Save squarepegsys/17fd6a6b030f8b11b579780d5b354994 to your computer and use it in GitHub Desktop.
Convert maven deps to gradle format
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 python | |
import xml.etree.ElementTree as ET | |
ns = {'pom': "http://maven.apache.org/POM/4.0.0" , } | |
def find_exclusions(exclusions): | |
for excl in exclusions.findall("pom:exclusion",ns): | |
yield excl | |
def add_exclusions(dep,action): | |
exclusions = dep.find("pom:exclusions",ns) | |
if (exclusions is None): | |
return action | |
action += "{\n" | |
for excl in find_exclusions(exclusions): | |
group = excl.find("pom:groupId",ns).text | |
artifact = excl.find("pom:artifactId",ns).text | |
action+=" exclude group:'%s', module:'%s'\n" %(group,artifact) | |
action+="}" | |
return action | |
if __name__=='__main__': | |
tree = ET.parse('pom.xml') | |
root = tree.getroot() | |
for dep in root.findall('.//pom:dependency',ns): | |
group = dep.find("pom:groupId",ns).text | |
artifact = dep.find("pom:artifactId",ns).text | |
version = dep.find("pom:version",ns).text | |
scope = dep.find("pom:scope",ns) | |
config = "compile" | |
if (scope is not None and scope.text=='test'): | |
config="testCompile" | |
action = "%s('%s:%s:%s')" %(config,group,artifact,version) | |
action = add_exclusions(dep,action) | |
print(action) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment