插件本身并没有真正提供,但您可以使用自己的版本匹配器获得它。
String getCurrentBranch(Project p) {
OutputStream out = new ByteArrayOutputStream()
p.exec {
commandLine = ['git', 'rev-parse', '--abbrev-ref', 'HEAD']
workingDir = projectToCheck.rootProject.projectDir
standardOutput = out
}
return out.toString().trim()
}
release {
versionPatterns = [
/(\d+)\.(\d+)\.(\d+)/: { Matcher m, Project p ->
if (getCurrentBranch(p) == 'master') {
m.replaceAll("${m[0][1]}.${(m[0][2] as int) + 1}.0")
} else {
m.replaceAll("${m[0][1]}.${m[0][2]}.${(m[0][3] as int) + 1}")
}
}
]
}
没有测试代码,但这就是我要走的路。