Skip to content

Commit

Permalink
Address deprecations after upgrading gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroBrine1st committed Jan 5, 2025
1 parent 5f55423 commit 584d41a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
25 changes: 10 additions & 15 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import com.android.build.api.dsl.VariantDimension
import java.io.ByteArrayOutputStream

plugins {
alias(libs.plugins.android.application)
Expand All @@ -12,6 +12,11 @@ plugins {
alias(libs.plugins.aboutlibraries)
}

val gitCommitShortHashProvider = providers.exec {
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
isIgnoreExitValue = false
}

android {
compileSdk = libs.versions.android.compileSdk.get().toInt()

Expand Down Expand Up @@ -82,7 +87,10 @@ android {
matchingFallbacks.add("release")
signingConfig = signingConfigs.getByName("debug")
applicationIdSuffix = ".nightly"
versionNameSuffix = "-${getCommitShortHash()}"
val shortHashResult = gitCommitShortHashProvider.result.get()
shortHashResult.rethrowFailure()
shortHashResult.assertNormalExitValue()
versionNameSuffix = "-${gitCommitShortHashProvider.standardOutput.asText.get().trim()}"
}
}
compileOptions {
Expand Down Expand Up @@ -200,18 +208,5 @@ ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}

fun executeCommand(vararg argv: String): String {
val byteArrayOutputStream = ByteArrayOutputStream()
exec {
commandLine = argv.toList()
standardOutput = byteArrayOutputStream
isIgnoreExitValue = false
}
return byteArrayOutputStream.toString()
}

fun getCommitShortHash(revision: String = "HEAD") =
executeCommand("git", "rev-parse", "--short", revision).trim()

fun VariantDimension.stringBuildConfigField(name: String, value: String) =
buildConfigField("String", name, "\"${value.replace("\"", "\\\"")}\"")
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {


tasks {
create<Delete>("clean") {
register<Delete>("clean") {
delete(layout.buildDirectory)
}
}

0 comments on commit 584d41a

Please sign in to comment.