Update MDC + Gradle and switch versioning to semver4j (#1306)

This commit is contained in:
Harsh Shandilya 2021-02-06 12:32:57 +05:30 committed by GitHub
parent 723acbf767
commit c021869f97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 27 deletions

View file

@ -35,6 +35,6 @@ dependencies {
implementation(Plugins.androidGradlePlugin) implementation(Plugins.androidGradlePlugin)
implementation(Plugins.binaryCompatibilityValidator) implementation(Plugins.binaryCompatibilityValidator)
implementation(Plugins.downloadTaskPlugin) implementation(Plugins.downloadTaskPlugin)
implementation(Plugins.jsemver)
implementation(Plugins.kotlinGradlePlugin) implementation(Plugins.kotlinGradlePlugin)
implementation(Plugins.semver4j)
} }

View file

@ -25,9 +25,9 @@ internal fun Project.configureForRootProject() {
delete(rootProject.buildDir) delete(rootProject.buildDir)
} }
tasks.withType<Wrapper> { tasks.withType<Wrapper> {
gradleVersion = "6.8.1" gradleVersion = "6.8.2"
distributionType = Wrapper.DistributionType.ALL distributionType = Wrapper.DistributionType.ALL
distributionSha256Sum = "3db89524a3981819ff28c3f979236c1274a726e146ced0c8a2020417f9bc0782" distributionSha256Sum = "1433372d903ffba27496f8d5af24265310d2da0d78bf6b4e5138831d4fe066e9"
} }
configureBinaryCompatibilityValidator() configureBinaryCompatibilityValidator()
} }

View file

@ -9,8 +9,8 @@ object Plugins {
val androidGradlePlugin = "com.android.tools.build:gradle:4.1.1" val androidGradlePlugin = "com.android.tools.build:gradle:4.1.1"
val binaryCompatibilityValidator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4" val binaryCompatibilityValidator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4"
val downloadTaskPlugin = "de.undercouch:gradle-download-task:4.1.1" val downloadTaskPlugin = "de.undercouch:gradle-download-task:4.1.1"
val jsemver = "com.github.zafarkhaja:java-semver:0.9.0"
val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
val semver4j = "com.vdurmont:semver4j:3.1.0"
} }
object Dependencies { object Dependencies {
@ -39,7 +39,7 @@ object Dependencies {
const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
const val lifecycle_viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" const val lifecycle_viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
const val material = "com.google.android.material:material:1.3.0-rc01" const val material = "com.google.android.material:material:1.3.0"
const val preference = "androidx.preference:preference:1.1.1" const val preference = "androidx.preference:preference:1.1.1"
const val recycler_view = "androidx.recyclerview:recyclerview:1.2.0-beta01" const val recycler_view = "androidx.recyclerview:recyclerview:1.2.0-beta01"
const val recycler_view_selection = "androidx.recyclerview:recyclerview-selection:1.1.0" const val recycler_view_selection = "androidx.recyclerview:recyclerview-selection:1.1.0"

View file

@ -5,7 +5,7 @@
import com.android.build.gradle.internal.plugins.AppPlugin import com.android.build.gradle.internal.plugins.AppPlugin
import com.github.zafarkhaja.semver.Version import com.vdurmont.semver4j.Semver
import java.io.OutputStream import java.io.OutputStream
import java.util.Properties import java.util.Properties
import org.gradle.api.Plugin import org.gradle.api.Plugin
@ -33,16 +33,16 @@ class VersioningPlugin : Plugin<Project> {
/** /**
* Generate the Android 'versionCode' property * Generate the Android 'versionCode' property
*/ */
private fun Version.androidCode(): Int { private fun Semver.androidCode(): Int {
return majorVersion * 1_00_00 + return major * 1_00_00 +
minorVersion * 1_00 + minor * 1_00 +
patchVersion patch
} }
/** /**
* Write an Android-specific variant of [this] to [stream] * Write an Android-specific variant of [this] to [stream]
*/ */
private fun Version.writeForAndroid(stream: OutputStream) { private fun Semver.writeForAndroid(stream: OutputStream) {
val newVersionCode = androidCode() val newVersionCode = androidCode()
val props = Properties() val props = Properties()
props.setProperty(VERSIONING_PROP_VERSION_CODE, "$newVersionCode") props.setProperty(VERSIONING_PROP_VERSION_CODE, "$newVersionCode")
@ -50,13 +50,6 @@ class VersioningPlugin : Plugin<Project> {
props.store(stream, VERSIONING_PROP_COMMENT) props.store(stream, VERSIONING_PROP_COMMENT)
} }
/**
* Returns the same [Version], but with build metadata stripped.
*/
private fun Version.clearPreRelease(): Version {
return Version.forIntegers(majorVersion, minorVersion, patchVersion)
}
override fun apply(project: Project) { override fun apply(project: Project) {
with(project) { with(project) {
val appPlugin = requireNotNull(plugins.findPlugin(AppPlugin::class.java)) { val appPlugin = requireNotNull(plugins.findPlugin(AppPlugin::class.java)) {
@ -77,35 +70,38 @@ class VersioningPlugin : Plugin<Project> {
appPlugin.extension.defaultConfig.versionName = versionName appPlugin.extension.defaultConfig.versionName = versionName
appPlugin.extension.defaultConfig.versionCode = versionCode appPlugin.extension.defaultConfig.versionCode = versionCode
afterEvaluate { afterEvaluate {
val version = Version.valueOf(versionName) val version = Semver(versionName)
tasks.register("clearPreRelease") { tasks.register("clearPreRelease") {
doLast { doLast {
version.clearPreRelease() version.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream()) .writeForAndroid(propFile.asFile.outputStream())
} }
} }
tasks.register("bumpMajor") { tasks.register("bumpMajor") {
doLast { doLast {
version.incrementMajorVersion() version.withIncMajor()
.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream()) .writeForAndroid(propFile.asFile.outputStream())
} }
} }
tasks.register("bumpMinor") { tasks.register("bumpMinor") {
doLast { doLast {
version.incrementMinorVersion() version.withIncMinor()
.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream()) .writeForAndroid(propFile.asFile.outputStream())
} }
} }
tasks.register("bumpPatch") { tasks.register("bumpPatch") {
doLast { doLast {
version.incrementPatchVersion() version.withIncPatch()
.withClearedSuffix()
.writeForAndroid(propFile.asFile.outputStream()) .writeForAndroid(propFile.asFile.outputStream())
} }
} }
tasks.register("bumpSnapshot") { tasks.register("bumpSnapshot") {
doLast { doLast {
version.incrementMinorVersion() version.withIncMinor()
.setPreReleaseVersion("SNAPSHOT") .withSuffix("SNAPSHOT")
.writeForAndroid(propFile.asFile.outputStream()) .writeForAndroid(propFile.asFile.outputStream())
} }
} }

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionSha256Sum=3db89524a3981819ff28c3f979236c1274a726e146ced0c8a2020417f9bc0782 distributionSha256Sum=1433372d903ffba27496f8d5af24265310d2da0d78bf6b4e5138831d4fe066e9
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists