@@ -24,22 +24,29 @@ import org.gradle.api.tasks.TaskAction
2424import org.gradle.kotlin.dsl.provideDelegate
2525
2626/* *
27- * Bumps the `version` property of the specified [versionFile].
27+ * Bumps the `version` property of the specified [versionFile], and sets the
28+ * `latestReleasedVersion`.
2829 *
2930 * Primarily utilized as a post-release clean up task in which we bump the versions of released
30- * modules to be one patch higher than their currently released counterparts.
31+ * modules to be one patch higher than their currently released counterparts, and update their
32+ * latest released version.
3133 *
3234 * @see PostReleasePlugin
3335 *
3436 * @property versionFile A [File] that contains the `version` property. Defaults to the
3537 * `gradle.properties` file at the project's root.
38+ * @property releasedVersion A [ModuleVersion] of what to bump from. Defaults to the project
39+ * version.
3640 * @property newVersion A [ModuleVersion] of what to set the version to. Defaults to one patch
37- * higher than the existing version.
41+ * higher than [releasedVersion]
3842 */
3943abstract class VersionBumpTask : DefaultTask () {
4044 @get: [Optional InputFile ]
4145 abstract val versionFile: Property <File >
4246
47+ @get: [Optional Input ]
48+ abstract val releasedVersion: Property <ModuleVersion >
49+
4350 @get: [Optional Input ]
4451 abstract val newVersion: Property <ModuleVersion >
4552
@@ -50,18 +57,23 @@ abstract class VersionBumpTask : DefaultTask() {
5057 @TaskAction
5158 fun build () {
5259 versionFile.get().rewriteLines {
53- if (it.startsWith(" version=" )) " version=${newVersion.get()} " else it
60+ when {
61+ it.startsWith(" version=" ) -> " version=${newVersion.get()} "
62+ it.startsWith(" latestReleasedVersion" ) -> " latestReleasedVersion=${releasedVersion.get()} "
63+ else -> it
64+ }
5465 }
5566 }
5667
5768 fun configure () {
5869 versionFile.convention(project.file(" gradle.properties" ))
59- newVersion.convention(computeNewVersion())
70+ releasedVersion.convention(computeReleasedVersion())
71+ newVersion.convention(releasedVersion.map { it.bump() })
6072 }
6173
62- fun computeNewVersion (): ModuleVersion ? {
74+ fun computeReleasedVersion (): ModuleVersion ? {
6375 val version: String? by project
6476
65- return version?.let { ModuleVersion .fromStringOrNull(it)?.bump() }
77+ return version?.let { ModuleVersion .fromStringOrNull(it) }
6678 }
6779}
0 commit comments