-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
87 lines (73 loc) · 2.73 KB
/
build.gradle.kts
File metadata and controls
87 lines (73 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Provider
import org.gradle.process.ExecOperations
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.io.ByteArrayOutputStream
import java.nio.charset.Charset
import javax.inject.Inject
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.protobuf) apply false
}
abstract class GitCommandValueSource :
ValueSource<String, GitCommandValueSource.Parameters> {
interface Parameters : ValueSourceParameters {
val args: ListProperty<String>
val workingDir: DirectoryProperty
}
@get:Inject
abstract val execOperations: ExecOperations
override fun obtain(): String {
val output = ByteArrayOutputStream()
execOperations.exec {
commandLine("git", *parameters.args.get().toTypedArray())
workingDir = parameters.workingDir.get().asFile
standardOutput = output
errorOutput = output
isIgnoreExitValue = true
}
return output
.toString(Charset.defaultCharset())
.trim()
}
}
fun git(vararg args: String) =
providers.of(GitCommandValueSource::class) {
parameters {
this.args.set(args.toList())
this.workingDir.set(layout.projectDirectory)
}
}
val gitCommitCountProvider = git("rev-list", "--count", "HEAD")
val gitCommitHashProvider = git("rev-parse", "--short=7", "HEAD")
data class GitInfo(
val commitCount: Int,
val shortHash: String,
val versionName: String
)
val gitInfoProvider: Provider<GitInfo> =
gitCommitCountProvider
.map { it.toIntOrNull() ?: 1 }
.zip(gitCommitHashProvider.map { it.ifBlank { "unknown" } }) { count, hash ->
GitInfo(
commitCount = count,
shortHash = hash,
versionName = "v3.6.1-$count-$hash"
)
}
val gitInfo: GitInfo = gitInfoProvider.get()
val androidMinSdkVersion by extra(27)
val androidTargetSdkVersion by extra(36)
val androidCompileSdkVersion by extra(36)
val androidBuildToolsVersion by extra("36.1.0")
val androidSourceCompatibility by extra(JavaVersion.VERSION_21)
val androidTargetCompatibility by extra(JavaVersion.VERSION_21)
val kotlinJvmTarget by extra(JvmTarget.JVM_21)
val appVersionCode: Int by extra(gitInfo.commitCount)
val appVersionName: String by extra(gitInfo.versionName)
val appGitHash: String by extra(gitInfo.shortHash)