#!/usr/bin/env python
#coding:utf-8
# Author:   xiaobaichuangtianxia--<>
# Purpose:  add jacoco dependency
# Created: 2017/10/12
import sys
import os
import xml.etree.ElementTree as ET


ET.register_namespace("", "http://maven.apache.org/POM/4.0.0")  #在parse之前调用    

tree = ET.ElementTree()
tree.parse("./pom.xml")  

root = tree.getroot()

for i in root:
    if("dependencies" in i.tag):
        newNode = ET.SubElement(i,'dependency')
        a = ET.SubElement(newNode,'groupId')
        b = ET.SubElement(newNode,'artifactId')
        c = ET.SubElement(newNode,'version')
        
        a.text = 'org.jacoco'
        a.tail = '\n'
        b.tail = '\n'
        c.tail = '\n'
        b.text = 'jacoco-maven-plugin'
        c.text = '0.7.9'
        newNode.tail = '\n'

    
tree.write("./pom.xml", encoding="utf-8",xml_declaration=True)   

  

posted on 2017-10-13 09:53  小白闯天下  阅读(349)  评论(0编辑  收藏  举报