Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
223 lines (192 loc) · 7.42 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
223 lines (192 loc) · 7.42 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
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
import java.io.FileInputStream
import java.util.*
plugins {
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
signing
`maven-publish`
`java-library`
id("com.diffplug.spotless") version "7.0.2"
}
group = "io.getstream"
description = "Stream official Java SDK"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation(libs.junit.jupiter)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
implementation("com.squareup.okhttp3:okhttp")
implementation("org.slf4j:slf4j-api:2.0.13")
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.2")
implementation("io.jsonwebtoken:jjwt-api:0.12.6")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.6")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.6")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("org.apache.commons:commons-lang3:3.18.0")
testImplementation("com.squareup.okhttp3:mockwebserver")
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
testCompileOnly("org.projectlombok:lombok:1.18.32")
testAnnotationProcessor("org.projectlombok:lombok:1.18.32")
}
val localProperties = Properties()
val localPropertiesFile = project.rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localProperties.load(localPropertiesFile.inputStream())
}
// `test` is the pull request gate, so it must not need credentials. Anything tagged
// `integration` talks to a live Stream app and runs in `integrationTest` instead. JUnit
// inherits the tag, so extending BasicTest is enough to land there.
tasks.named<Test>("test") {
useJUnitPlatform {
excludeTags("integration")
}
doFirst {
// Inject local properties into tests runtime system properties
localProperties.forEach { (k, v) ->
systemProperty(k.toString(), v.toString())
}
}
}
// Not wired into `check`, so `./gradlew build` stays offline.
tasks.register<Test>("integrationTest") {
group = "verification"
description = "Runs the tests that talk to a live Stream app."
testClassesDirs = sourceSets["test"].output.classesDirs
classpath = sourceSets["test"].runtimeClasspath
useJUnitPlatform {
includeTags("integration")
}
doFirst {
localProperties.forEach { (k, v) ->
systemProperty(k.toString(), v.toString())
}
}
}
val generatedVersionDir = layout.buildDirectory.dir("generated-version")
// Not "version.properties" at the jar root. stream-chat-java ships that same name, and
// ClassLoader.getResourceAsStream returns whichever jar comes first.
val sdkVersionResource = "io/getstream/stream-sdk-java/version.properties"
tasks.register("generateVersionProperties") {
doLast {
val propertiesFile =
layout.buildDirectory.file("generated-version/$sdkVersionResource").get().asFile
propertiesFile.parentFile.mkdirs()
val properties = Properties()
properties.setProperty("version", version.toString())
propertiesFile.writer().use { properties.store(it, null) }
}
}
sourceSets {
main {
output.dir(mapOf("builtBy" to "generateVersionProperties"), generatedVersionDir)
}
}
spotless {
java {
googleJavaFormat("1.28.0")
}
}
extra["ossrhUsername"] = ""
extra["ossrhPassword"] = ""
extra["signing.keyId"] = ""
extra["signing.password"] = ""
extra["signing.secretKeyRingFile"] = ""
extra["sonatypeStagingProfileId"] = ""
extra["signing.gpgkeycontents"] = ""
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
val properties = Properties()
FileInputStream(secretPropsFile).use { properties.load(it) }
properties.forEach { (name, value) -> extra[name.toString()] = value.toString() }
} else {
// Use system environment variables
extra["ossrhUsername"] = System.getenv("OSSRH_USERNAME") ?: ""
extra["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") ?: ""
extra["signing.keyId"] = System.getenv("SIGNING_KEY_ID") ?: ""
extra["signing.password"] = System.getenv("SIGNING_PASSWORD") ?: ""
extra["signing.gpgkeycontents"] = System.getenv("GPG_KEY_CONTENTS") ?: ""
extra["sonatypeStagingProfileId"] = System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: ""
}
publishing {
publications {
create<MavenPublication>("maven") {
artifactId = "stream-sdk-java"
from(components["java"])
pom {
name.set("Stream official Java SDK")
description.set("Stream Java SDK")
url.set("https://github.com/getstream/stream-sdk-java")
licenses {
license {
name.set("Stream License")
url.set("https://github.com/GetStream/stream-sdk-java/blob/main/LICENSE")
}
}
developers {
developer {
id.set("getstream-support")
name.set("Stream Support")
email.set("support@getstream.io")
}
}
scm {
url = "https://github.com/GetStream/stream-sdk-java"
connection = "scm:git:github.com/getstream/stream-java-sdk.git"
developerConnection = "scm:git:github.com/getstream/stream-java-sdk.git"
}
}
}
}
}
// Where to publish: "streamRepo", "central", or both, comma-separated. CI always passes it;
// with nothing passed this stays on Central so a local publishToMavenLocal behaves as before.
// streamRepo stages a Maven-2 tree under build/staged-repo for a separate upload job.
val publishTargets = providers.gradleProperty("streamPublishTargets")
.getOrElse("central")
.split(",")
.map(String::trim)
.filter(String::isNotEmpty)
.toSet()
require(publishTargets.isNotEmpty() && (publishTargets - setOf("central", "streamRepo")).isEmpty()) {
"'streamPublishTargets' must be a comma-separated subset of central, streamRepo but was '$publishTargets'"
}
if ("streamRepo" in publishTargets) {
publishing {
repositories {
maven {
name = "streamRepoStaging"
url = layout.buildDirectory.dir("staged-repo").get().asFile.toURI()
}
}
}
}
signing {
useInMemoryPgpKeys(
extra["signing.keyId"] as String,
extra["signing.gpgkeycontents"] as String,
extra["signing.password"] as String
)
sign(publishing.publications)
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
username = extra["ossrhUsername"] as String
password = extra["ossrhPassword"] as String
stagingProfileId = extra["sonatypeStagingProfileId"] as String
}
}
}