Skip to content

Instantly share code, notes, and snippets.

@squarepegsys
Created July 5, 2018 17:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarepegsys/17fd6a6b030f8b11b579780d5b354994 to your computer and use it in GitHub Desktop.
Save squarepegsys/17fd6a6b030f8b11b579780d5b354994 to your computer and use it in GitHub Desktop.
Convert maven deps to gradle format
#!/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