-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
256 lines (212 loc) · 7.92 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.ltgt.gradle.errorprone.errorprone
plugins {
java
signing
`java-library`
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("net.ltgt.errorprone") version "4.0.1"
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
fun getProjectProperty(name: String) = project.properties[name] as? String
group = "xyz.dynxsty"
val archivesBaseName = "dih4jda"
version = "1.6.2"
val javaVersion: JavaVersion = JavaVersion.current()
var isCI: Boolean = System.getProperty("GIT_COMMIT") != null // jitpack
|| System.getenv("GIT_COMMIT") != null
|| System.getProperty("GITHUB_ACTIONS") != null // GitHub Actions
|| System.getenv("GITHUB_ACTIONS") != null
/*
Add the manualCI property to your gradle.properties
Sets failOnError on the javadocJar tasks to your specified boolean.
*/
if (getProjectProperty("manualCI") != null) {
isCI = getProjectProperty("manualCI").toBoolean()
}
configure<SourceSetContainer> {
register("examples") {
java.srcDir("src/examples/java")
compileClasspath += sourceSets["main"].output
runtimeClasspath += sourceSets["main"].output
}
}
repositories {
mavenCentral()
maven(url = "https://m2.dv8tion.net/releases")
maven(url = "https://jitpack.io")
}
val lombokVersion = "1.18.34"
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.11.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.11.0")
testImplementation("ch.qos.logback:logback-classic:1.5.8")
api("net.dv8tion:JDA:5.1.1") {
exclude(module = "opus-java")
}
//code saftey
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
errorprone("com.google.errorprone:error_prone_core:2.30.0")
//Lombok's annotations
compileOnly("org.projectlombok:lombok:$lombokVersion")
annotationProcessor("org.projectlombok:lombok:$lombokVersion")
testCompileOnly("org.projectlombok:lombok:$lombokVersion")
testAnnotationProcessor("org.projectlombok:lombok:$lombokVersion")
//Sets the dependencies for the examples
configurations["examplesImplementation"].withDependencies {
addAll(configurations["implementation"].allDependencies)
addAll(configurations["compileOnly"].allDependencies)
}
}
val jar: Jar by tasks
val shadowJar: ShadowJar by tasks
val javadoc: Javadoc by tasks
val build: Task by tasks
shadowJar.archiveClassifier.set("withDependencies")
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
//enable this when the StaticAssignmentInConstructor error-prone error is fixed
//if (isCI) options.compilerArgs.add("-Werror")
//error-prone configuration
options.errorprone.disableWarningsInGeneratedCode.set(true)
options.errorprone.errorproneArgs.addAll(
"-Xep:AnnotateFormatMethod:OFF", "-Xep:FutureReturnValueIgnored:OFF", "-Xep:NotJavadoc:OFF")
}
val javadocJar = task<Jar>("javadocJar") {
from("src/main/java")
dependsOn(javadoc)
archiveClassifier.set("javadoc")
from(javadoc.destinationDir)
}
//Needed for some reason by maven central
val sourcesJar = task<Jar>("sourcesJar") {
archiveClassifier.set("sources")
from("src/main/java")
}
/*
To find all missing javadocs / all javadocs warnings execute this command:
./gradlew javadocJar --warning-mode all --stacktrace
*/
javadoc.apply {
isFailOnError = isCI
//Fixes the error where the executor could not be found and the build fails.
if (javaVersion <= JavaVersion.VERSION_20) {
isFailOnError = false
}
options.memberLevel = JavadocMemberLevel.PUBLIC
options.encoding = "UTF-8"
(options as? StandardJavadocDocletOptions)?.let { opt ->
opt.addStringOption("charSet", "UTF-8")
// Fix for https://stackoverflow.com/questions/52326318/maven-javadoc-search-redirects-to-undefined-url
if (javaVersion in JavaVersion.VERSION_11..JavaVersion.VERSION_12) {
opt.addBooleanOption("-no-module-directories", true)
}
// Java 13 changed accessibility rules.
// On versions less than Java 13, we simply ignore the errors.
if (javaVersion >= JavaVersion.VERSION_13) {
opt.addBooleanOption("Xdoclint:all", true)
} else {
//Can be ignored because JavaDocs are generated using Java 21.
opt.addBooleanOption("Xdoclint:all,-missing,-accessibility", true)
}
}
dependsOn(sourcesJar)
source = sourcesJar.source.asFileTree
exclude("MANIFEST.MF")
}
build.apply {
dependsOn(jar)
dependsOn(sourcesJar)
dependsOn(javadocJar)
dependsOn(shadowJar)
}
////////////////////////////////////////
////////////////////////////////////////
//// ////
//// Publishing And Signing ////
//// ////
////////////////////////////////////////
////////////////////////////////////////
buildscript {
repositories {
mavenCentral()
}
}
publishing {
publications {
register("Release", MavenPublication::class) {
from(components["java"])
artifactId = archivesBaseName
groupId = group as String
version = version as String
artifact(javadocJar)
artifact(sourcesJar)
//Creating the pom required for maven central
pom {
packaging = "jar"
name.set(archivesBaseName)
description.set("A fairly easy-to-use command framework for the Java Discord API, with support for " +
"Slash Commands and Context Commands")
url.set("https://github.com/DynxstyGIT/DIH4JDA")
scm {
url.set("https://github.com/DynxstyGIT/DIH4JDA")
connection.set("scm:git:git://github.com/DynxstyGIT/DIH4JDA")
developerConnection.set("scm:git:ssh:[email protected]:DynxstyGIT/DIH4JDA")
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("Dynxsty")
name.set("Jason Dean Lessenich")
email.set("[email protected]")
}
developer {
id.set("Denux")
name.set("Timon Thomas Klinkert")
email.set("[email protected]")
}
}
}
}
}
}
nexusPublishing.repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
// Turn off sign tasks if we don't have a key
val canSign: Boolean = getProjectProperty("signing.keyId") != null
if (canSign) {
signing {
useGpgCmd()
sign(publishing.publications)
sign(configurations.archives.get())
}
}
tasks.create("release") {
// Only close repository after release is published
val closeSonatypeStagingRepository by tasks
closeSonatypeStagingRepository.mustRunAfter(tasks.withType<PublishToMavenRepository>())
dependsOn(tasks.withType<PublishToMavenRepository>())
// Closes the sonatype repository and publishes to maven central
val closeAndReleaseSonatypeStagingRepository: Task by tasks
dependsOn(closeAndReleaseSonatypeStagingRepository)
// Builds all jars for publications
dependsOn(build)
}