1.全局方法
为项目范围创建的,即.全局可用于项目,可以在构建脚本中的任何位置使用myMethod(p1, p2)等效的方式调用project.myMethod(p1, p2)
ext.myMethod = { param1, param2 ->
// Method body here
}
ext.hg = [
cloneOrPull: { source, dest, branch ->
if (!dest.isDirectory())
hg.clone(source, dest, branch)
else
hg.pull(dest)
hg.update(dest, branch)
},
clone: { source, dest, branch ->
dest.mkdirs()
exec {
commandLine 'hg', 'clone', '--noupdate', source, dest.absolutePath
}
},
pull: { dest ->
exec {
workingDir dest.absolutePath
commandLine 'hg', 'pull'
}
},
]
调用方式:
hg.clone('path/to/repo')
本文介绍了一种在Gradle项目中使用的HG插件实现方案。该插件提供了全局方法和一系列Mercurial操作,包括克隆、更新、拉取等。通过简单的API调用即可完成版本控制任务。
2716

被折叠的 条评论
为什么被折叠?



