Update MDC + Gradle and switch versioning to semver4j (#1306)
This commit is contained in:
parent
723acbf767
commit
c021869f97
5 changed files with 23 additions and 27 deletions
|
@ -35,6 +35,6 @@ dependencies {
|
|||
implementation(Plugins.androidGradlePlugin)
|
||||
implementation(Plugins.binaryCompatibilityValidator)
|
||||
implementation(Plugins.downloadTaskPlugin)
|
||||
implementation(Plugins.jsemver)
|
||||
implementation(Plugins.kotlinGradlePlugin)
|
||||
implementation(Plugins.semver4j)
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ internal fun Project.configureForRootProject() {
|
|||
delete(rootProject.buildDir)
|
||||
}
|
||||
tasks.withType<Wrapper> {
|
||||
gradleVersion = "6.8.1"
|
||||
gradleVersion = "6.8.2"
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
distributionSha256Sum = "3db89524a3981819ff28c3f979236c1274a726e146ced0c8a2020417f9bc0782"
|
||||
distributionSha256Sum = "1433372d903ffba27496f8d5af24265310d2da0d78bf6b4e5138831d4fe066e9"
|
||||
}
|
||||
configureBinaryCompatibilityValidator()
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ object Plugins {
|
|||
val androidGradlePlugin = "com.android.tools.build:gradle:4.1.1"
|
||||
val binaryCompatibilityValidator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4"
|
||||
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 semver4j = "com.vdurmont:semver4j:3.1.0"
|
||||
}
|
||||
|
||||
object Dependencies {
|
||||
|
@ -39,7 +39,7 @@ object Dependencies {
|
|||
const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$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 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 recycler_view = "androidx.recyclerview:recyclerview:1.2.0-beta01"
|
||||
const val recycler_view_selection = "androidx.recyclerview:recyclerview-selection:1.1.0"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
|
||||
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.util.Properties
|
||||
import org.gradle.api.Plugin
|
||||
|
@ -33,16 +33,16 @@ class VersioningPlugin : Plugin<Project> {
|
|||
/**
|
||||
* Generate the Android 'versionCode' property
|
||||
*/
|
||||
private fun Version.androidCode(): Int {
|
||||
return majorVersion * 1_00_00 +
|
||||
minorVersion * 1_00 +
|
||||
patchVersion
|
||||
private fun Semver.androidCode(): Int {
|
||||
return major * 1_00_00 +
|
||||
minor * 1_00 +
|
||||
patch
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 props = Properties()
|
||||
props.setProperty(VERSIONING_PROP_VERSION_CODE, "$newVersionCode")
|
||||
|
@ -50,13 +50,6 @@ class VersioningPlugin : Plugin<Project> {
|
|||
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) {
|
||||
with(project) {
|
||||
val appPlugin = requireNotNull(plugins.findPlugin(AppPlugin::class.java)) {
|
||||
|
@ -77,35 +70,38 @@ class VersioningPlugin : Plugin<Project> {
|
|||
appPlugin.extension.defaultConfig.versionName = versionName
|
||||
appPlugin.extension.defaultConfig.versionCode = versionCode
|
||||
afterEvaluate {
|
||||
val version = Version.valueOf(versionName)
|
||||
val version = Semver(versionName)
|
||||
tasks.register("clearPreRelease") {
|
||||
doLast {
|
||||
version.clearPreRelease()
|
||||
version.withClearedSuffix()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
}
|
||||
tasks.register("bumpMajor") {
|
||||
doLast {
|
||||
version.incrementMajorVersion()
|
||||
version.withIncMajor()
|
||||
.withClearedSuffix()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
}
|
||||
tasks.register("bumpMinor") {
|
||||
doLast {
|
||||
version.incrementMinorVersion()
|
||||
version.withIncMinor()
|
||||
.withClearedSuffix()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
}
|
||||
tasks.register("bumpPatch") {
|
||||
doLast {
|
||||
version.incrementPatchVersion()
|
||||
version.withIncPatch()
|
||||
.withClearedSuffix()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
}
|
||||
tasks.register("bumpSnapshot") {
|
||||
doLast {
|
||||
version.incrementMinorVersion()
|
||||
.setPreReleaseVersion("SNAPSHOT")
|
||||
version.withIncMinor()
|
||||
.withSuffix("SNAPSHOT")
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
}
|
||||
|
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=3db89524a3981819ff28c3f979236c1274a726e146ced0c8a2020417f9bc0782
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip
|
||||
distributionSha256Sum=1433372d903ffba27496f8d5af24265310d2da0d78bf6b4e5138831d4fe066e9
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
Loading…
Reference in a new issue