Set version without build start time in debug build

36ba6c3b2c5f21c8d4326129eebc6192144474ac
This commit is contained in:
bacecek
2024-03-19 14:28:36 +03:00
parent c0f4e45b3e
commit ecfa554881
6 changed files with 34 additions and 18 deletions
+2 -12
View File
@@ -1,22 +1,12 @@
import com.yandex.div.gradle.FileExtensions
import com.yandex.div.gradle.PublicationType
apply from: "$projectDir/version.gradle"
def publicationType = project.findProperty("publicationType")
def regularVersion = project.findProperty("regularVersion")
ext {
minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34
buildToolsVersion = "34.0.0"
if (regularVersion == null) {
divkitVersionName = "${divkitVersion.versionName}${PublicationType.fromString(publicationType).getVersionSuffix()}"
} else {
divkitVersionName = "${divkitVersion.versionName}-regular-$regularVersion"
}
}
buildscript {
@@ -124,13 +114,13 @@ apiValidation {
task reportVersion {
doLast {
println "DivKit version ${rootProject.property('divkitVersionName')}"
println "DivKit version ${divkitVersion.releaseLibraryVersion}"
}
}
task reportBuildNumber {
doLast {
println "buildNumber ${rootProject.property('divkitVersionName')}"
println "buildNumber ${divkitVersion.releaseLibraryVersion}"
}
}
@@ -5,15 +5,28 @@ import org.gradle.api.Project
class Version private constructor(
val majorVersion: Int,
val minorVersion: Int,
val fixVersion: Int
val fixVersion: Int,
) {
val versionCode = computeVersionCode(majorVersion, minorVersion, fixVersion)
val versionName = "$majorVersion.$minorVersion.$fixVersion"
val baseVersionName = "$majorVersion.$minorVersion.$fixVersion"
var buildNumber = 0
private set
var releaseLibraryVersion: String = baseVersionName
private set
fun getVersionNameForBuildType(buildType: String): String {
return if (buildType == "debug") {
// releaseLibraryVersion can contains build start time (see PublicationType.dev)
// which will be different for each build. This will cause recompilation on each build.
baseVersionName
} else {
releaseLibraryVersion
}
}
constructor(
project: Project,
majorVersion: Int,
@@ -26,6 +39,14 @@ class Version private constructor(
val tsrBuildNumber = System.getenv("BUILD_NUMBER")
buildNumber = tsrBuildNumber?.toInt() ?: 0
}
val publicationType = PublicationType.fromString(project.findProperty("publicationType") as String?)
val regularVersion = project.findProperty("regularVersion") as String?
releaseLibraryVersion = if (regularVersion != null) {
"${baseVersionName}-regular-$regularVersion"
} else {
"${baseVersionName}${publicationType.getVersionSuffix()}"
}
}
companion object {
+1 -1
View File
@@ -15,7 +15,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionName divkitVersion.versionName
versionName divkitVersion.baseVersionName
versionCode divkitVersion.versionCode
vectorDrawables.useSupportLibrary = true
+6 -1
View File
@@ -1,3 +1,4 @@
import com.android.build.api.variant.BuildConfigField
import groovy.json.JsonOutput
apply from: "${project.projectDir}/../div-library.gradle"
@@ -16,10 +17,14 @@ android {
defaultConfig {
buildConfigField "String", "DIV2_JSON_PATH", JsonOutput.toJson(crossplatformProjectDir)
buildConfigField "String", "VERSION_NAME", JsonOutput.toJson(rootProject.property('divkitVersionName'))
}
}
androidComponents.onVariants(androidComponents.selector().all()) {
def versionName = divkitVersion.getVersionNameForBuildType(buildType)
buildConfigFields.put("VERSION_NAME", new BuildConfigField("String", JsonOutput.toJson(versionName), null))
}
dependencies {
implementation project(path: ':assertion')
implementation project(path: ':div-json')
+1 -1
View File
@@ -13,7 +13,7 @@ afterEvaluate {
publications {
release(MavenPublication) {
from components.release
version divkitVersionName
version divkitVersion.releaseLibraryVersion
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ afterEvaluate {
artifact sourcesJar
artifact javadocJar
from components.java
version divkitVersionName
version divkitVersion.releaseLibraryVersion
}
}
}