forked from discord-jda/JDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
476 lines (379 loc) · 13.3 KB
/
build.gradle.kts
File metadata and controls
476 lines (379 loc) · 13.3 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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import de.undercouch.gradle.tasks.download.Download
import net.dv8tion.jda.tasks.*
import nl.littlerobots.vcu.plugin.resolver.VersionSelectors
import org.apache.tools.ant.filters.ReplaceTokens
import org.jreleaser.gradle.plugin.tasks.AbstractJReleaserTask
import org.jreleaser.model.Active
plugins {
environment
artifacts
`java-library`
`maven-publish`
alias(libs.plugins.shadow)
alias(libs.plugins.versions)
alias(libs.plugins.version.catalog.update)
alias(libs.plugins.jreleaser)
alias(libs.plugins.download)
}
////////////////////////////////////
// //
// Project Configuration //
// //
////////////////////////////////////
projectEnvironment {
version = Version(major = "6", minor = "1", revision = "1", classifier = null)
}
artifactFilters {
opusExclusions.addAll("natives/**", "com/sun/jna/**", "club/minnced/opus/util/*", "tomp2p/opuswrapper/*")
additionalAudioExclusions.addAll("com/google/crypto/tink/**", "com/google/gson/**", "com/google/protobuf/**", "google/protobuf/**")
}
// Use normal version string for new releases and commitHash for other builds
if (projectEnvironment.canPublish) {
project.version = projectEnvironment.version.get().toString()
} else {
project.version = "${projectEnvironment.version.get()}_${projectEnvironment.commitHash}"
}
project.group = "org.redlance.thirdparty"
base {
archivesName.set("JDA")
}
configure<SourceSetContainer> {
register("examples") {
java.srcDir("src/examples/java")
compileClasspath += sourceSets["main"].output
runtimeClasspath += sourceSets["main"].output
}
}
////////////////////////////////////
// //
// Dependency Configuration //
// //
////////////////////////////////////
val mockitoAgent by configurations.creating
repositories {
mavenCentral()
}
dependencies {
/* ABI dependencies */
//Code safety
compileOnly(libs.findbugs)
compileOnly(libs.jetbrains.annotations)
//Logger
api(libs.slf4j)
//Web Connection Support
api(libs.websocket.client)
api(libs.okhttp)
//Opus library support
api(libs.opus)
//Collections Utility
api(libs.commons.collections)
//we use this only together with opus-java
// if that dependency is excluded it also doesn't need jna anymore
// since jna is a transitive runtime dependency of opus-java we don't include it explicitly as dependency
compileOnly(libs.jna)
/* Internal dependencies */
//General Utility
implementation(libs.trove4j)
implementation(libs.bundles.jackson)
//Audio crypto libraries
implementation(libs.tink)
//Sets the dependencies for the examples
configurations["examplesImplementation"].withDependencies {
addAll(configurations["api"].allDependencies)
addAll(configurations["implementation"].allDependencies)
addAll(configurations["compileOnly"].allDependencies)
}
testImplementation(libs.bundles.junit)
testImplementation(libs.reflections)
testImplementation(libs.mockito)
testImplementation(libs.assertj)
testImplementation(libs.commons.lang3)
testImplementation(libs.logback.classic)
testImplementation(libs.archunit)
mockitoAgent(libs.mockito) {
isTransitive = false
}
// OpenRewrite
// Import Rewrite's bill of materials.
testImplementation(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.6.1"))
// rewrite-java dependencies only necessary for Java Recipe development
testImplementation("org.openrewrite:rewrite-java")
testImplementation("org.openrewrite.recipe:rewrite-java-dependencies")
// This is supposed to only be the version that corresponds to the current Java version,
// but as there are no toolchain, we include all, they can coexist safely tho.
testRuntimeOnly("org.openrewrite:rewrite-java-8")
testRuntimeOnly("org.openrewrite:rewrite-java-11")
testRuntimeOnly("org.openrewrite:rewrite-java-17")
// For authoring tests for any kind of Recipe
testImplementation("org.openrewrite:rewrite-test")
}
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
isNonStable(candidate.version)
}
gradleReleaseChannel = "current"
}
versionCatalogUpdate {
versionSelector(VersionSelectors.STABLE)
}
////////////////////////////////////
// //
// Build Task Configuration //
// //
////////////////////////////////////
val jar by tasks.getting(Jar::class) {
archiveBaseName.set(project.name)
manifest.attributes("Implementation-Version" to project.version, "Automatic-Module-Name" to "net.dv8tion.jda")
}
val shadowJar by tasks.getting(ShadowJar::class) {
archiveClassifier.set("withDependencies")
exclude("*.pom")
}
val sourcesForRelease by tasks.registering(Copy::class) {
from("src/main/java") {
include("**/JDAInfo.java")
val version = projectEnvironment.version.get()
val tokens = mapOf(
"versionMajor" to version.major,
"versionMinor" to version.minor,
"versionRevision" to version.revision,
"versionClassifier" to nullableReplacement(version.classifier),
"commitHash" to projectEnvironment.commitHash
)
// Allow for setting null on some strings without breaking the source
// for this, we have special tokens marked with "!@...@!" which are replaced to @...@
filter { it.replace(Regex("\"!@|@!\""), "@") }
// Then we can replace the @...@ with the respective values here
filter<ReplaceTokens>("tokens" to tokens)
}
into("build/filteredSrc")
includeEmptyDirs = false
}
val generateJavaSources by tasks.registering(SourceTask::class) {
val javaSources = sourceSets["main"].allJava.filter {
it.name != "JDAInfo.java"
}.asFileTree
source = javaSources + fileTree(sourcesForRelease.get().destinationDir)
dependsOn(sourcesForRelease)
}
val noOpusJar by tasks.registering(ShadowJar::class) {
dependsOn(shadowJar)
archiveClassifier.set(shadowJar.archiveClassifier.get() + "-no-opus")
configurations = shadowJar.configurations
from(sourceSets["main"].output)
applyOpusExclusions(artifactFilters)
manifest.from(jar.manifest)
}
val minimalJar by tasks.registering(ShadowJar::class) {
dependsOn(shadowJar)
minimize()
archiveClassifier.set(shadowJar.archiveClassifier.get() + "-min")
configurations = shadowJar.configurations
from(sourceSets["main"].output)
applyAudioExclusions(artifactFilters)
manifest.from(jar.manifest)
}
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from("src/main/java") {
exclude("**/JDAInfo.java")
}
from(sourcesForRelease.get().destinationDir)
dependsOn(sourcesForRelease)
}
val javadoc by tasks.getting(Javadoc::class) {
isFailOnError = projectEnvironment.isGithubAction
(options as? StandardJavadocDocletOptions)?.apply {
memberLevel = JavadocMemberLevel.PUBLIC
encoding = "UTF-8"
author()
tags("incubating:a:Incubating:")
links("https://docs.oracle.com/javase/8/docs/api/", "https://takahikokawasaki.github.io/nv-websocket-client/")
addStringOption("-release", "8")
addBooleanOption("Xdoclint:all,-missing", true)
overview = "$projectDir/overview.html"
}
dependsOn(generateJavaSources)
source = generateJavaSources.get().source
exclude {
it.file.absolutePath.contains("internal", ignoreCase=false)
}
}
val javadocJar by tasks.registering(Jar::class) {
dependsOn(javadoc)
archiveClassifier.set("javadoc")
from(javadoc.destinationDir)
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.isIncremental = true
val args = mutableListOf("-Xlint:deprecation", "-Xlint:unchecked")
options.release = 8
options.compilerArgs.addAll(args)
}
val compileJava by tasks.getting(JavaCompile::class) {
dependsOn(generateJavaSources)
source = generateJavaSources.get().source
}
tasks.build.configure {
dependsOn(jar)
dependsOn(javadocJar)
dependsOn(sourcesJar)
dependsOn(shadowJar)
dependsOn(noOpusJar)
dependsOn(minimalJar)
jar.mustRunAfter(tasks.clean)
shadowJar.mustRunAfter(sourcesJar)
}
////////////////////////////////////
// //
// Test Configuration //
// //
////////////////////////////////////
val downloadRecipeClasspath by tasks.registering(Download::class) {
val targetVersion = "5.6.1"
src("https://repo.maven.apache.org/maven2/net/dv8tion/JDA/$targetVersion/JDA-$targetVersion.jar")
dest("src/test/resources/META-INF/rewrite/classpath/JDA-$targetVersion.jar")
overwrite(false)
}
tasks.named("processTestResources").configure {
dependsOn(downloadRecipeClasspath)
}
tasks.register<Test>("updateTestSnapshots") {
group = "verification"
useJUnitPlatform()
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
systemProperty("updateSnapshots", "true")
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
failFast = false
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_21)) {
jvmArgs = listOf("-javaagent:${mockitoAgent.asPath}")
}
}
tasks.test {
testLogging {
events("passed", "skipped", "failed")
}
reports {
junitXml.required = projectEnvironment.isGithubAction
html.required = projectEnvironment.isGithubAction
}
}
val verifyBytecodeVersion by tasks.registering(VerifyBytecodeVersion::class) {
group = "verification"
expectedMajorVersion = 52
classes.from(compileJava.outputs.files.asFileTree.matching {
include("**/*.class")
})
}
compileJava.finalizedBy(verifyBytecodeVersion)
////////////////////////////////////
// //
// Publishing And Signing //
// //
////////////////////////////////////
// Generate pom file for maven central
fun MavenPom.populate() {
packaging = "jar"
name.set(project.name)
description.set("Java wrapper for the popular chat & VOIP service: Discord https://discord.com")
url.set("https://github.com/discord-jda/JDA")
scm {
url.set("https://github.com/discord-jda/JDA")
connection.set("scm:git:git://github.com/discord-jda/JDA")
developerConnection.set("scm:git:ssh:git@github.com:discord-jda/JDA")
}
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("Minn")
name.set("Florian Spieß")
email.set("business@minn.dev")
}
developer {
id.set("DV8FromTheWorld")
name.set("Austin Keener")
email.set("keeneraustin@yahoo.com")
}
}
}
shadow {
addShadowVariantIntoJavaComponent = false
}
val stagingDirectory = layout.buildDirectory.dir("staging-deploy").get()
publishing {
publications {
register<MavenPublication>("Release") {
from(components["java"])
artifactId = project.name
groupId = project.group as String
version = project.version as String
artifact(sourcesJar)
artifact(javadocJar)
pom.populate()
}
}
repositories.maven {
url = stagingDirectory.asFile.toURI()
}
}
jreleaser {
project {
versionPattern = "CUSTOM"
}
release {
github {
enabled = false
}
}
signing {
active = Active.RELEASE
armored = true
}
deploy {
maven {
mavenCentral {
register("sonatype") {
active = Active.RELEASE
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(stagingDirectory.asFile.relativeTo(projectDir).path)
}
}
}
}
}
tasks.withType<AbstractJReleaserTask>().configureEach {
mustRunAfter(tasks.named("publish"))
}