-
Notifications
You must be signed in to change notification settings - Fork 43
/
build.gradle
149 lines (133 loc) · 5.29 KB
/
build.gradle
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
buildscript {
ext.modules = [
"sdkVersionName" : "2.0.0-beta2-SNAPSHOT",
"demoAppVersionCode" : 4,
"androidMinSdkVersion": 23,
"androidTargetVersion": 35,
"androidCompileSdk": 35,
"sourceCompatibility": JavaVersion.VERSION_1_8,
"targetCompatibility": JavaVersion.VERSION_1_8,
"kotlinJvmTarget": JavaVersion.VERSION_1_8.toString(),
"kotlinToolchainLanguageVersion": JavaLanguageVersion.of(17)
]
}
plugins {
alias libs.plugins.android.application apply false
alias libs.plugins.android.library apply false
alias libs.plugins.dagger.hilt apply false
alias libs.plugins.detekt
alias libs.plugins.gradlePlayPublisher apply false
alias libs.plugins.kotlinAndroid apply false
alias libs.plugins.kotlinParcelize apply false
alias libs.plugins.kotlinKapt apply false
alias libs.plugins.nexus.publishPlugin
}
version modules.sdkVersionName // we add it here so that nexus automatically chooses staging or snapshot repo
nexusPublishing {
repositories {
sonatype {
username = System.getenv('SONATYPE_NEXUS_USERNAME') ?: ''
password = System.getenv('SONATYPE_NEXUS_PASSWORD') ?: ''
repositoryDescription = "Paypal Android SDK"
packageGroup = "com.paypal"
}
}
transitionCheckOptions {
// give nexus sonatype more time to close the staging repository
delayBetween.set(Duration.ofSeconds(20))
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
detektPlugins libs.detekt.formatting
detektPlugins libs.detekt.rulesLibraries
}
detekt {
toolVersion = libs.versions.detektVersion.get()
config = files("detekt/detekt-config.yml")
input = files(
"CorePayments/src",
"CardPayments/src",
"PayPalWebPayments/src",
"FraudProtection/src",
"Demo/src"
)
autoCorrect = project.hasProperty('detektAutoCorrect')
reports {
html {
enabled = true
destination = file("build/reports/detekt_report.html")
}
}
}
subprojects {
group = "com.paypal.android"
}
task incrementSnapshotVersion {
doLast {
def topLevelGradleFile = file('./build.gradle')
def topLevelGradleFileText = topLevelGradleFile.getText('UTF-8')
def matcher = topLevelGradleFileText =~ /"sdkVersionName"\s*: "(.*)",/
def versionString = matcher[0][1]
def (major, minor, patch) = versionString.tokenize('.')
// check if patch version ends with beta and a single/multi-digit number
def isBetaVersion = patch.matches(/[0-9]+-beta\d+$/)
if (isBetaVersion) {
def betaMatcher = patch =~ /[0-9]+-beta(\d+)$/
def betaVersion = betaMatcher[0][1].toInteger()
// capture beginning of beta patch string and increment beta version
def newBeta = patch.replaceFirst(/([0-9.]+-beta)\d+$/, '$1' + (betaVersion + 1))
def newVersion = "$major.$minor.${newBeta}-SNAPSHOT"
def updatedScript =
topLevelGradleFileText.replaceFirst(/("sdkVersionName"\s*: )".*",/, '$1"' + newVersion + '",')
topLevelGradleFile.write(updatedScript, 'UTF-8')
} else {
def patchInteger = (patch.endsWith('-SNAPSHOT') ? patch - '-SNAPSHOT' : patch).toInteger()
def newVersion = "$major.$minor.${patchInteger + 1}-SNAPSHOT"
def updatedScript =
topLevelGradleFileText.replaceFirst(/("sdkVersionName"\s*: )".*",/, '$1"' + newVersion + '",')
topLevelGradleFile.write(updatedScript, 'UTF-8')
}
}
}
//./gradlew -PversionParam=0.0.1 changeReleaseVersion
task changeReleaseVersion {
doLast {
def topLevelGradleFile = file('./build.gradle')
def topLevelGradleFileText = topLevelGradleFile.getText('UTF-8')
def updatedScript =
topLevelGradleFileText.replaceFirst(/("sdkVersionName"\s*: )".*",/, '$1"' + versionParam + '",')
topLevelGradleFile.write(updatedScript, 'UTF-8')
}
}
task getDemoAppVersionCode {
doLast {
def topLevelGradleFile = file('./build.gradle')
def topLevelGradleFileText = topLevelGradleFile.getText('UTF-8')
def matcher = topLevelGradleFileText =~ /"demoAppVersionCode"\s*: ([0-9]*),/
def versionCode = matcher[0][1].toInteger()
println(versionCode)
}
}
//./gradlew -PdemoAppVersionCodeParam=0.0.1 changeReleaseVersion
task setDemoAppVersionCode {
doLast {
def topLevelGradleFile = file('./build.gradle')
def topLevelGradleFileText = topLevelGradleFile.getText('UTF-8')
def updatedScript =
topLevelGradleFileText.replaceFirst(/("demoAppVersionCode"\s*: )[0-9]*,/, '$1' + demoAppVersionCodeParam + ',')
topLevelGradleFile.write(updatedScript, 'UTF-8')
}
}
//./gradlew -PversionParam=0.0.1 changeReleaseVersion
task updateCHANGELOGVersion {
doLast {
def date = new Date()
def formattedDate = date.format('yyyy-MM-dd')
def changelogFile = new File('CHANGELOG.md')
def changelogFileText = changelogFile.text.replaceFirst("## unreleased", "## " + versionParam + " ($formattedDate)")
changelogFile.write(changelogFileText)
}
}