-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild.gradle
271 lines (240 loc) · 7.61 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
buildscript {
repositories {
mavenCentral()
google()
}
ext.kotlin_version = "1.6.21"
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.4"
classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:5.3.0"
classpath "com.nabilhachicha:android-native-dependencies:0.1.2"
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1"
}
}
plugins {
id "com.github.ben-manes.versions" version "0.39.0"
id "ru.vyarus.animalsniffer" version "1.5.0"
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
ext {
android_build_tools_version = "30.0.2"
android_compile_sdk_version = 33
android_min_sdk_version = 24
android_target_sdk_version = 35
// Required for some dependencies only available from our private S3
//
nyplS3Depend =
project.findProperty('org.librarysimplified.s3.depend') as Boolean
nyplS3AccessKey =
project.findProperty('org.librarysimplified.s3.access_key_id') ?: ''
nyplS3SecretKey =
project.findProperty('org.librarysimplified.s3.secret_access_key') ?: ''
if (nyplS3Depend && !nyplS3AccessKey) {
throw new GradleException(
"""\
'org.librarysimplified.s3.access_key_id' is undefined!
^ required by 'org.librarysimplified.s3.access_key_id'\
""".stripIndent())
}
if (nyplS3Depend && !nyplS3SecretKey) {
throw new GradleException(
"""\
'org.librarysimplified.s3.secret_access_key' is undefined!
^ required by 'org.librarysimplified.s3.depend'\
""".stripIndent())
}
// Required by some projects to build with drm support
//
nyplDrmEnabled =
project.findProperty('org.librarysimplified.drm.enabled') as Boolean
if (nyplDrmEnabled && !nyplS3Depend) {
throw new GradleException(
"""\
'org.librarysimplified.s3.depend' is undefined!
^ required by 'org.librarysimplified.drm.enabled'\
""".stripIndent())
}
//
// Check that non -SNAPSHOT builds don't use -SNAPSHOT dependencies.
//
final String versionName = project.ext["VERSION_NAME"]
final Set<String> snapshots = new HashSet<>()
if (!versionName.endsWith("-SNAPSHOT")) {
final List<String> versionAliases = libs.getVersionAliases()
versionAliases.each { name ->
final java.util.Optional<VersionConstraint> versionConstraintOpt = libs.findVersion(name)
if (versionConstraintOpt.isPresent()) {
final VersionConstraint versionConstraint = versionConstraintOpt.get()
if (versionConstraint.requiredVersion.endsWith("-SNAPSHOT")) {
snapshots.add("$name ${versionConstraint.requiredVersion}")
}
}
}
if (!snapshots.isEmpty()) {
final StringBuilder builder = new StringBuilder();
builder.append("The current non-SNAPSHOT build (")
builder.append(versionName)
builder.append(") depends on the following -SNAPSHOT dependencies:")
builder.append("\n")
snapshots.each { version ->
builder.append(" ")
builder.append(version)
builder.append("\n")
}
final String text = builder.toString()
logger.error("{}", text)
throw new GradleException(text);
}
}
}
subprojects { project ->
group = project.ext["GROUP"]
version = project.ext["VERSION_NAME"]
switch (POM_PACKAGING) {
case "aar":
apply from: file("$rootDir/build_aar.gradle")
break
case "apk":
apply from: file("$rootDir/build_apk.gradle")
break
case "jar":
apply from: file("$rootDir/build_jar.gradle")
break
default:
throw new IllegalStateException(
"Unrecognized packaging type ${POM_PACKAGING} for ${project}")
}
/*
* Configure publishing for the various project types.
*/
switch (POM_PACKAGING) {
case "jar":
apply from: file("$rootDir/build_publishing.gradle")
break
case "apk":
break
case "aar":
apply from: file("$rootDir/build_publishing.gradle")
break
default:
throw new IllegalStateException(
"Unrecognized packaging type ${POM_PACKAGING} for ${project}")
}
repositories {
mavenLocal()
mavenCentral()
google()
/*
* S3 repositories for restricted DRM artifacts.
*/
if (nyplDrmEnabled) {
maven {
name = "S3 Snapshots"
url = "s3://simplye-maven-builds/snapshots/"
credentials(AwsCredentials) {
accessKey = nyplS3AccessKey
secretKey = nyplS3SecretKey
}
mavenContent {
snapshotsOnly()
}
}
maven {
name = "S3 Releases"
url = "s3://simplye-maven-builds/releases/"
credentials(AwsCredentials) {
accessKey = nyplS3AccessKey
secretKey = nyplS3SecretKey
}
mavenContent {
releasesOnly()
}
}
}
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven {
url "http://maven.findawayworld.com/artifactory/libs-release/"
allowInsecureProtocol true
}
maven { url "https://jitpack.io" }
jcenter()
}
// Skip tasks for projects that require drm; unless drm is enabled
//
def nyplDrmRequired =
project.findProperty('org.librarysimplified.drm.required') as Boolean
if (nyplDrmRequired) {
project.tasks.all { task ->
task.onlyIf { nyplDrmEnabled }
}
}
// This resolution strategy is required in order to pick up Readium's fork of nanohttpd.
// This must remain until will update Readium. See migration guide: https://github.com/readium/kotlin-toolkit/releases/tag/2.2.1
if (nyplDrmEnabled || !nyplDrmRequired) {
project.configurations.all {
resolutionStrategy {
dependencySubstitution {
all { DependencySubstitution dependency ->
if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.group == 'com.github.edrlab.nanohttpd') {
dependency.useTarget ('com.github.readium.nanohttpd:' + dependency.requested.module + ':' + dependency.requested.version, 'because nanohttpd ownership changed from edrlab to readium')
}
}
}
}
}
}
}
/**
* An empty task called by CI. We don't do semantic versioning analysis here yet.
*/
task verifySemanticVersioning {}
/**
* Displays properties starting with 'org.librarysimplified'.
*/
task listProperties(group: 'NYPL') {
description = "Displays properties starting with 'org.librarysimplified'."
doLast {
project.properties
.findAll { p ->
p.key.startsWith('org.librarysimplified')
}
.sort()
.each { println(it) }
}
}
/*
* Add ktlint tasks.
*/
apply from: file("$rootDir/build_ktlint.gradle")
subprojects {
assemble.dependsOn ktlint
}
/**
* Expand the 'tilde' character to user.home.
*/
@SuppressWarnings('unused')
static String expandUserHome(String path) {
if (path == null) return
return path.replaceFirst("~", System.getProperty("user.home"))
}
@SuppressWarnings('unused')
static Integer calculateVersionCode(Project project) {
def now = LocalDateTime.now(ZoneId.of("UTC"))
def nowSeconds = now.toEpochSecond(ZoneOffset.UTC)
// Seconds since 2021-03-15 09:20:00 UTC
def nowReduced = nowSeconds - 1615800000
return nowReduced
}
task listrepos {
doLast {
println "Repositories:"
project.repositories.each { println "Name: " + it.name + "; url: " + it.url }
}
}