gradle-release
gradle-release copied to clipboard
I have a new idea to incorporate this feature into the plugin for the purpose of using dynamic version dependencies
The extension function of this plug-in I used and another plug-in can be extended to resolve the latest.release dependency version to the real version number when tagging, and restore the latest.release function when switching to the next snapshot version. I think it is necessary for the author to integrate this function into the plugin if he has time.
- import this plugin
id 'com.github.ben-manes.versions' version "${versions_plugin_version}"
- Naming rules for version number variable names Plugin version number:artifactID_plugin_version Regular version number:artifactID_version
- extended content
release{
tasks.register('extractLatestReleaseProperty') {
doLast {
def directoryPath = "${buildDir}/latestReleaseProperty"
def directory = new File(directoryPath)
if (!directory.exists()) {
directory.mkdirs()
println "Directory created: $directoryPath"
} else {
println "Directory already exists: $directoryPath"
}
def outputFilePath = "${directoryPath}/report.txt"
def properties = new Properties()
properties.load(new FileInputStream('gradle.properties'))
def propertyKeys = []
properties.each { key, value ->
if (value == 'latest.release') {
propertyKeys << key
}
}
file(outputFilePath).write(propertyKeys.join('\n'))
println "Latest release property extracted and saved to: $outputFilePath"
}
}
tasks.register('changeRealVersion') {
doLast {
def latestReleaseList = new File("${buildDir}/latestReleaseProperty/report.txt")
.readLines();
def realReleaseList = new File("${buildDir}/dependencyUpdates/report.txt").readLines().findAll { line ->
line.contains(' - ')
}
Properties gradleProperties = new Properties()
File propertiesFile = file("gradle.properties")
gradleProperties.load(propertiesFile.newDataInputStream())
latestReleaseList
.each { latestReleaseLine ->
realReleaseList.each { realReleaseLine ->
if (latestReleaseLine.contains('plugin')) {
if (realReleaseLine.contains(latestReleaseLine.replace('_plugin_version', '').replaceAll('_', '-'))) {
gradleProperties.setProperty(latestReleaseLine, realReleaseLine.substring(realReleaseLine.lastIndexOf(":") + 1))
return
}
} else {
if (realReleaseLine.contains(latestReleaseLine.replace('_version', '').replaceAll('_', '-'))) {
gradleProperties.setProperty(latestReleaseLine, realReleaseLine.substring(realReleaseLine.lastIndexOf(":") + 1))
return
}
}
}
}
FileOutputStream output = new FileOutputStream(propertiesFile)
gradleProperties.store(output, null)
output.close()
}
}
tasks.register('recoveryLatestReleaseVersion') {
doLast {
def latestReleaseList = new File("${buildDir}/latestReleaseProperty/report.txt")
.readLines();
Properties gradleProperties = new Properties()
File propertiesFile = file("gradle.properties")
gradleProperties.load(propertiesFile.newDataInputStream())
latestReleaseList.each { latestReleaseLine ->
gradleProperties.setProperty(latestReleaseLine, 'latest.release')
}
FileOutputStream output = new FileOutputStream(propertiesFile)
gradleProperties.store(output, null)
output.close()
}
}
tasks {
dependencyUpdates.dependsOn clean
extractLatestReleaseProperty.dependsOn dependencyUpdates
createScmAdapter.dependsOn extractLatestReleaseProperty
unSnapshotVersion.dependsOn changeRealVersion
updateVersion.dependsOn recoveryLatestReleaseVersion
commitNewVersion.dependsOn clean
}
}
These only contain my additions