forked from square/wire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
243 lines (221 loc) · 7.52 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
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
dependencies {
classpath(libs.animalSniffer.gradle)
classpath(libs.dokka.core)
classpath(libs.dokka.gradlePlugin)
classpath(libs.pluginz.android)
classpath(libs.pluginz.japicmp)
classpath(libs.pluginz.kotlin)
classpath(libs.pluginz.kotlinSerialization)
classpath(libs.pluginz.shadow)
classpath(libs.pluginz.spotless)
classpath(libs.protobuf.gradlePlugin)
classpath(libs.vanniktechPublishPlugin)
classpath(libs.pluginz.buildConfig)
classpath(libs.wire.gradlePlugin)
classpath("com.google.guava:guava:31.1-jre")
classpath("org.ow2.asm:asm:9.1")
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
}
rootProject.plugins.withType(NodeJsRootPlugin::class) {
// 16+ required for Apple Silicon support
// https://youtrack.jetbrains.com/issue/KT-49109#focus=Comments-27-5259190.0-0
rootProject.extensions.getByType(NodeJsRootExtension::class).nodeVersion = "16.13.1"
}
apply(plugin = "com.vanniktech.maven.publish.base")
allprojects {
group = project.property("GROUP") as String
version = project.property("VERSION_NAME") as String
repositories {
mavenCentral()
google()
}
// Prefer to get dependency versions from BOMs.
configurations.all {
val configuration = this
configuration.dependencies.all {
val bom = when (group) {
"com.squareup.okio" -> libs.okio.bom.get()
"com.squareup.okhttp3" -> libs.okhttp.bom.get()
else -> return@all
}
configuration.dependencies.add(project.dependencies.platform(bom))
}
}
}
subprojects {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
setEnforceCheck(false)
kotlin {
target("**/*.kt")
ktlint(libs.versions.ktlint.get()).userData(kotlin.collections.mapOf("indent_size" to "2"))
trimTrailingWhitespace()
endWithNewline()
toggleOffOn()
}
}
// The `application` plugin internally applies the `distribution` plugin and
// automatically adds tasks to create/publish tar and zip artifacts.
// https://docs.gradle.org/current/userguide/application_plugin.html
// https://docs.gradle.org/current/userguide/distribution_plugin.html#sec:publishing_distributions_upload
plugins.withType(DistributionPlugin::class) {
tasks.findByName("distTar")?.enabled = false
tasks.findByName("distZip")?.enabled = false
configurations["archives"].artifacts.removeAll {
val file: File = it.file
file.name.contains("tar") || file.name.contains("zip")
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
// Disable optimized callable references. See https://youtrack.jetbrains.com/issue/KT-37435
freeCompilerArgs += "-Xno-optimized-callable-references"
}
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
options.encoding = Charsets.UTF_8.toString()
}
tasks.withType<Test> {
testLogging {
events(STARTED, PASSED, SKIPPED, FAILED)
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = false
}
}
if (!(
project.name.endsWith("-swift") ||
project.name.endsWith("-bom") ||
project.name.endsWith("-benchmarks") ||
project.name.contains("golden") ||
project.name.contains("protoc") ||
project.displayName.contains("sample")
)) {
apply(plugin = "checkstyle")
afterEvaluate {
configure<CheckstyleExtension> {
toolVersion = "7.7"
sourceSets = listOf(project.extensions.getByType<SourceSetContainer>()["main"])
}
}
}
}
allprojects {
// Prefer to get dependency versions from BOMs.
configurations.all {
val configuration = this
configuration.dependencies.all {
val bom = when (group) {
"com.squareup.okio" -> libs.okio.bom.get()
"com.squareup.okhttp3" -> libs.okhttp.bom.get()
else -> return@all
}
configuration.dependencies.add(project.dependencies.platform(bom))
}
}
tasks.withType<Jar>().configureEach {
if (name == "jar") {
manifest {
attributes("Automatic-Module-Name" to project.name)
}
}
}
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(8)
perPackageOption {
matchingRegex.set("com\\.squareup\\.wire\\.internal.*")
suppress.set(true)
}
}
if (name == "dokkaGfm") {
outputDirectory.set(project.file("${project.rootDir}/docs/3.x"))
}
}
plugins.withId("com.vanniktech.maven.publish.base") {
configure<PublishingExtension> {
repositories {
maven {
name = "test"
setUrl("file://${project.rootProject.buildDir}/localMaven")
}
/**
* Want to push to an internal repository for testing?
* Set the following properties in ~/.gradle/gradle.properties.
*
* internalUrl=YOUR_INTERNAL_URL
* internalUsername=YOUR_USERNAME
* internalPassword=YOUR_PASSWORD
*/
val internalUrl = providers.gradleProperty("internalUrl")
if (internalUrl.isPresent) {
maven {
name = "internal"
setUrl(internalUrl)
credentials(PasswordCredentials::class)
}
}
}
}
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.S01)
val inMemoryKey = project.findProperty("signingInMemoryKey") as String?
if (!inMemoryKey.isNullOrEmpty()) {
signAllPublications()
}
pom {
description.set("gRPC and protocol buffers for Android, Kotlin, and Java.")
name.set(project.name)
url.set("https://github.com/square/wire/")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("square")
name.set("Square, Inc.")
}
}
scm {
url.set("https://github.com/square/wire/")
connection.set("scm:git:https://github.com/square/wire.git")
developerConnection.set("scm:git:ssh://[email protected]/square/wire.git")
}
}
}
}
}
tasks.register("publishPluginToGradlePortalIfRelease") {
val VERSION_NAME: String by project
// Snapshots cannot be released to the Gradle portal. And we don't want to release internal square
// builds.
if (VERSION_NAME.endsWith("-SNAPSHOT") || VERSION_NAME.contains("square")) return@register
dependsOn(":wire-gradle-plugin:publishPlugins")
}
apply(from = "gen-tests.gradle.kts")