我定义了一个读取属性文件并更新某个字段的任务。我只想在执行'release'时运行,而不是在'build'期间运行。如何在构建期间排除Gradle任务或方法
我用这gradle这个释放插件版本:https://github.com/researchgate/gradle-release
这个插件将更新gradle.properties文件到下一个版本的版本,每个版本。我需要保留当前的版本号,因此我写了这个方法。
但是,无论何时执行构建,都会执行此任务。我试图将其更改为方法,并在'uploadArchives'内调用该方法,我认为这只在“发布”期间运行。但没有结果。它继续在每个构建上执行!
如何从'build'中排除它并仅在发布的情况下调用它?
这里是任务和一些代码片段:
task restoreCurrentVersion {
try {
String key = 'currentVersion'
File propertiesFile = project(':commons').file("gradle.properties")
String currentVersion = project(':commons').version
this.ant.replaceregexp(file: propertiesFile, byline: true) {
regexp(pattern: "^(\\s*)$key(\\s*)=(\\s*).+")
substitution(expression: "\\1$key\\2=\\3$currentVersion")
}
} catch (BuildException be) {
throw new GradleException('Unable to write version property.', be)
}
}
uploadArchives {
repositories.mavenDeployer {
repository(url: 'file://Users/my.home/.m2/repository/')
}
// restoreCurrentVersion() //Uncommenting this makes the method (when converted the above task to a method) to execute always
}
createReleaseTag.dependsOn uploadArchives
ext.'release.useAutomaticVersion' = "true"