forked from apollographql/apollo-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
365 lines (311 loc) · 11.3 KB
/
build.gradle.kts
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
project.apply {
from(rootProject.file("gradle/dependencies.gradle"))
}
repositories {
maven { url = uri("https://plugins.gradle.org/m2/") }
google()
jcenter()
}
dependencies {
classpath(groovy.util.Eval.x(project, "x.dep.okHttp.okHttp4"))
classpath(groovy.util.Eval.x(project, "x.dep.android.plugin"))
classpath(groovy.util.Eval.x(project, "x.dep.gradleErrorpronePlugin"))
classpath(groovy.util.Eval.x(project, "x.dep.gradleJapiCmpPlugin"))
classpath(groovy.util.Eval.x(project, "x.dep.kotlin.plugin"))
classpath(groovy.util.Eval.x(project, "x.dep.kotlin.plugin"))
classpath(groovy.util.Eval.x(project, "x.dep.sqldelight.plugin"))
}
}
val rootJapiCmp = tasks.register("japicmp")
abstract class DownloadFileTask : DefaultTask() {
@get:Input
abstract val url: Property<String>
@get:org.gradle.api.tasks.OutputFile
abstract val output: RegularFileProperty
@TaskAction
fun taskAction() {
val client = okhttp3.OkHttpClient()
val request = okhttp3.Request.Builder().get().url(url.get()).build()
client.newCall(request).execute().body!!.byteStream().use { body ->
output.asFile.get().outputStream().buffered().use { file ->
body.copyTo(file)
}
}
}
}
subprojects {
apply {
from(rootProject.file("gradle/dependencies.gradle"))
}
buildscript {
repositories {
maven { url = uri("https://plugins.gradle.org/m2/") }
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
google()
}
}
plugins.withType(com.android.build.gradle.BasePlugin::class.java) {
(project.extensions.getByName("android") as com.android.build.gradle.BaseExtension).compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
plugins.withType(org.gradle.api.plugins.JavaPlugin::class.java) {
extensions.configure(JavaPluginExtension::class.java) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
tasks.withType<Test> {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
}
this.apply(plugin = "maven-publish")
repositories {
maven { url = uri("https://plugins.gradle.org/m2/") }
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
google()
maven { url = uri("https://jitpack.io") }
}
apply(plugin = "net.ltgt.errorprone")
configurations.named("errorprone") {
resolutionStrategy.force(groovy.util.Eval.x(this@subprojects, "x.dep.errorProneCore"))
}
val downloadBaselineJarTaskProvider = tasks.register("downloadBaseLineJar", DownloadFileTask::class.java) {
val group = project.property("GROUP") as String
val artifact = project.property("POM_ARTIFACT_ID") as String
val version = "1.2.1"
val jar = "$artifact-$version.jar"
url.set("https://jcenter.bintray.com/${group.replace(".", "/")}/$artifact/$version/$jar")
output.set(File(buildDir, "japicmp/cache/$jar"))
}
// TODO: Make this lazy
val jarTask = [email protected]("jar") as? org.gradle.jvm.tasks.Jar
if (jarTask != null) {
val japiCmp = [email protected]("japicmp", me.champeau.gradle.japicmp.JapicmpTask::class.java) {
dependsOn(downloadBaselineJarTaskProvider)
oldClasspath = [email protected](downloadBaselineJarTaskProvider.get().output.asFile.get())
newClasspath = [email protected](jarTask.archiveFile)
ignoreMissingClasses = true
packageExcludes = listOf("*.internal*")
onlyModified = true
txtOutputFile = [email protected]("$buildDir/reports/japi.txt")
}
rootJapiCmp.configure {
dependsOn(japiCmp)
}
}
}
group = property("GROUP")!!
version = property("VERSION_NAME")!!
apply(plugin = "checkstyle")
extensions.findByType(CheckstyleExtension::class.java)!!.apply {
configFile = rootProject.file("checkstyle.xml")
configProperties = mapOf(
"checkstyle.cache.file" to rootProject.file("build/checkstyle.cache")
)
}
tasks.register("checkstyle", Checkstyle::class.java) {
source("src/main/java")
include("**/*.java")
classpath = files()
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-XepDisableWarningsInGeneratedCode")
}
afterEvaluate {
tasks.findByName("check")?.dependsOn("checkstyle")
}
tasks.withType<Test>().configureEach {
systemProperty("updateTestFixtures", System.getProperty("updateTestFixtures"))
}
afterEvaluate {
configurePublishing()
}
}
fun Project.configurePublishing() {
val android = extensions.findByType(com.android.build.gradle.BaseExtension::class.java)
/**
* Javadoc
*/
var javadocTask = tasks.findByName("javadoc") as Javadoc?
var javadocJarTaskProvider: TaskProvider<org.gradle.jvm.tasks.Jar>? = null
if (javadocTask == null && android != null) {
javadocTask = tasks.create("javadoc", Javadoc::class.java) {
source = android.sourceSets["main"].java.sourceFiles
classpath += project.files(android.getBootClasspath().joinToString(File.pathSeparator))
}
}
if (javadocTask != null) {
javadocJarTaskProvider = tasks.register("javadocJar", org.gradle.jvm.tasks.Jar::class.java) {
archiveClassifier.set("javadoc")
dependsOn(javadocTask)
from(javadocTask.destinationDir)
}
}
var sourcesJarTaskProvider: TaskProvider<org.gradle.jvm.tasks.Jar>? = null
val javaPluginConvention = project.convention.findPlugin(JavaPluginConvention::class.java)
if (javaPluginConvention != null && android == null) {
sourcesJarTaskProvider = tasks.register("sourcesJar", org.gradle.jvm.tasks.Jar::class.java) {
archiveClassifier.set("sources")
from(javaPluginConvention.sourceSets.get("main").allSource)
}
} else if (android != null) {
sourcesJarTaskProvider = tasks.register("sourcesJar", org.gradle.jvm.tasks.Jar::class.java) {
archiveClassifier.set("sources")
from(android.sourceSets["main"].java.sourceFiles)
}
}
tasks.withType(Javadoc::class.java) {
// TODO: fix the javadoc warnings
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}
configure<PublishingExtension> {
publications {
when {
plugins.hasPlugin("org.jetbrains.kotlin.multiplatform") -> {
withType<MavenPublication>().getByName("jvm") {
// multiplatform doesn't add javadoc by default so add it here
if (javadocJarTaskProvider != null) {
artifact(javadocJarTaskProvider.get())
}
}
}
plugins.hasPlugin("java-gradle-plugin") -> {
// java-gradle-plugin doesn't add javadoc/sources by default so add it here
withType<MavenPublication>().all {
if (name == "pluginMaven") {
if (javadocJarTaskProvider != null) {
artifact(javadocJarTaskProvider.get())
}
if (sourcesJarTaskProvider != null) {
artifact(sourcesJarTaskProvider.get())
}
}
}
}
else -> {
create<MavenPublication>("default") {
val javaComponent = components.findByName("java")
if (javaComponent != null) {
from(javaComponent)
} else if (android != null) {
afterEvaluate {
from(components.findByName("release"))
}
}
if (javadocJarTaskProvider != null) {
artifact(javadocJarTaskProvider.get())
}
if (sourcesJarTaskProvider != null) {
artifact(sourcesJarTaskProvider.get())
}
pom {
artifactId = findProperty("POM_ARTIFACT_ID") as String?
}
}
}
}
withType<MavenPublication>() {
setDefaultPomFields()
}
}
repositories {
maven {
name = "pluginTest"
url = uri("file://${rootProject.buildDir}/localMaven")
}
maven {
name = "bintray"
url = uri("https://api.bintray.com/maven/apollographql/android/apollo/;publish=1;override=1")
credentials {
username = System.getenv("BINTRAY_USER")
password = System.getenv("BINTRAY_API_KEY")
}
}
maven {
name = "ojo"
url = uri("https://oss.jfrog.org/artifactory/oss-snapshot-local/")
credentials {
username = System.getenv("BINTRAY_USER")
password = System.getenv("BINTRAY_API_KEY")
}
}
maven {
name = "oss"
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = System.getenv("SONATYPE_NEXUS_USERNAME")
password = System.getenv("SONATYPE_NEXUS_PASSWORD")
}
}
}
}
}
/**
* Set fields which are common to all project, either KMP or non-KMP
*/
fun PublicationContainer.setDefaultPomFields() {
withType<MavenPublication>().all {
pom {
groupId = findProperty("GROUP") as String?
version = findProperty("VERSION_NAME") as String?
name.set(findProperty("POM_NAME") as String?)
packaging = findProperty("POM_PACKAGING") as String?
description.set(findProperty("POM_DESCRIPTION") as String?)
url.set(findProperty("POM_URL") as String?)
scm {
url.set(findProperty("POM_SCM_URL") as String?)
connection.set(findProperty("POM_SCM_CONNECTION") as String?)
developerConnection.set(findProperty("POM_SCM_DEV_CONNECTION") as String?)
}
licenses {
license {
name.set(findProperty("POM_LICENCE_NAME") as String?)
url.set(findProperty("POM_LICENCE_URL") as String?)
}
}
developers {
developer {
id.set(findProperty("POM_DEVELOPER_ID") as String?)
name.set(findProperty("POM_DEVELOPER_NAME") as String?)
}
}
}
}
}
fun subprojectTasks(name: String): List<Task> {
return subprojects.flatMap { subproject ->
subproject.tasks.matching {it.name == name }
}
}
tasks.register("publishIfNeeded") {
val eventName = System.getenv("GITHUB_EVENT_NAME")
val ref = System.getenv("GITHUB_REF")
doFirst {
project.logger.log(LogLevel.LIFECYCLE, "publishIfNeeded eventName=$eventName ref=$ref")
}
if (eventName == "push" && ref == "refs/heads/master") {
project.logger.log(LogLevel.LIFECYCLE, "Deploying snapshot to OJO...")
dependsOn(subprojectTasks("publishAllPublicationsToOjoRepository"))
project.logger.log(LogLevel.LIFECYCLE, "Deploying snapshot to OSS...")
dependsOn(subprojectTasks("publishAllPublicationsToOssRepository"))
}
if (ref?.startsWith("refs/tags/") == true) {
project.logger.log(LogLevel.LIFECYCLE, "Deploying release to Bintray...")
dependsOn(subprojectTasks("publishAllPublicationsToBintrayRepository"))
project.logger.log(LogLevel.LIFECYCLE, "Deploying release to Gradle Portal...")
dependsOn(":apollo-gradle-plugin:publishPlugins")
}
}