forked from MinnDevelopment/discord-webhooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
243 lines (202 loc) · 6.69 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 org.apache.tools.ant.filters.ReplaceTokens
import java.io.ByteArrayOutputStream
import java.time.Duration
plugins {
`java-library`
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}
val major = "0"
val minor = "7"
val patch = "3"
group = "club.minnced"
version = "$major.$minor.$patch"
fun getCommit()
= System.getenv("GITHUB_SHA")
?: System.getenv("GIT_COMMIT")
?: try {
val out = ByteArrayOutputStream()
exec {
commandLine("git rev-parse --verify --short HEAD".split(" "))
standardOutput = out
workingDir = projectDir
}
out.toString("UTF-8").trim()
} catch (ignored: Throwable) { "N/A" }
val tokens = mapOf(
"MAJOR" to major,
"MINOR" to minor,
"PATCH" to patch,
"VERSION" to version,
"COMMIT" to getCommit()
)
repositories {
mavenCentral()
}
val versions = mapOf(
"slf4j" to "1.7.32",
"okhttp" to "3.14.9",
"json" to "20210307",
"jda" to "5.0.0-alpha.1",
"discord4j" to "3.2.1",
"javacord" to "3.3.2",
"junit" to "4.13.2",
"mockito" to "3.6.28", // must be compatible with powermock
"powermock" to "2.0.9",
"logback" to "1.2.3",
"annotations" to "22.0.0"
)
dependencies {
api("org.slf4j:slf4j-api:${versions["slf4j"]}")
api("com.squareup.okhttp3:okhttp:${versions["okhttp"]}")
api("org.json:json:${versions["json"]}")
implementation("org.jetbrains:annotations:${versions["annotations"]}")
compileOnly("net.dv8tion:JDA:${versions["jda"]}")
compileOnly("com.discord4j:discord4j-core:${versions["discord4j"]}")
compileOnly("org.javacord:javacord:${versions["javacord"]}")
testImplementation("junit:junit:${versions["junit"]}")
testImplementation("org.mockito:mockito-core:${versions["mockito"]}")
testImplementation("org.powermock:powermock-module-junit4:${versions["powermock"]}")
testImplementation("org.powermock:powermock-api-mockito2:${versions["powermock"]}")
testImplementation("net.dv8tion:JDA:${versions["jda"]}")
testImplementation("com.discord4j:discord4j-core:${versions["discord4j"]}")
testImplementation("org.javacord:javacord:${versions["javacord"]}")
//testCompile("ch.qos.logback:logback-classic:${versions["logback"]}")
}
fun getProjectProperty(name: String) = project.properties[name] as? String
val javadoc: Javadoc by tasks
val jar: Jar by tasks
val sources = tasks.create("sources", Copy::class.java) {
from("src/main/java")
into("$buildDir/sources")
filter<ReplaceTokens>("tokens" to tokens)
}
javadoc.dependsOn(sources)
javadoc.source = fileTree(sources.destinationDir)
if (!System.getProperty("java.version").startsWith("1.8"))
(javadoc.options as CoreJavadocOptions).addBooleanOption("html5", true)
val javadocJar = tasks.create("javadocJar", Jar::class.java) {
dependsOn(javadoc)
from(javadoc.destinationDir)
archiveClassifier.set("javadoc")
}
val sourcesJar = tasks.create("sourcesJar", Jar::class.java) {
dependsOn(sources)
from(sources.destinationDir)
archiveClassifier.set("sources")
}
tasks.withType<JavaCompile> {
val arguments = mutableListOf("-Xlint:deprecation,unchecked,divzero,cast,static,varargs,try")
options.isIncremental = true
options.encoding = "UTF-8"
if (JavaVersion.current().isJava9Compatible) doFirst {
arguments += "--release"
arguments += "8"
}
doFirst {
options.compilerArgs = arguments
}
}
val compileJava: JavaCompile by tasks
compileJava.apply {
source = fileTree(sources.destinationDir)
dependsOn(sources)
}
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
val test: Task by tasks
val build: Task by tasks
build.apply {
dependsOn(javadocJar)
dependsOn(sourcesJar)
dependsOn(jar)
dependsOn(test)
}
// Generate pom file for maven central
fun generatePom(): MavenPom.() -> Unit {
return {
packaging = "jar"
name.set(project.name)
description.set("Provides easy to use bindings for the Discord Webhook API")
url.set("https://github.com/MinnDevelopment/discord-webhooks")
scm {
url.set("https://github.com/MinnDevelopment/discord-webhooks")
connection.set("scm:git:git://github.com/MinnDevelopment/discord-webhooks")
developerConnection.set("scm:git:ssh:[email protected]:MinnDevelopment/discord-webhooks")
}
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("[email protected]")
}
}
}
}
// Publish
publishing {
publications {
register("Release", MavenPublication::class) {
from(components["java"])
artifactId = project.name
groupId = project.group as String
version = project.version as String
artifact(sourcesJar)
artifact(javadocJar)
pom.apply(generatePom())
}
}
}
// Staging and Promotion
if ("signing.keyId" in properties) {
signing {
sign(publishing.publications["Release"])
}
}
nexusPublishing {
repositories.sonatype {
username.set(getProjectProperty("ossrhUser"))
password.set(getProjectProperty("ossrhPassword"))
stagingProfileId.set(getProjectProperty("stagingProfileId"))
}
// Sonatype is very slow :)
connectTimeout.set(Duration.ofMinutes(1))
clientTimeout.set(Duration.ofMinutes(10))
transitionCheckOptions {
maxRetries.set(100)
delayBetween.set(Duration.ofSeconds(5))
}
}
// To publish run ./gradlew release
val rebuild = tasks.create("rebuild") {
val clean = tasks.getByName("clean")
dependsOn(build)
dependsOn(clean)
build.mustRunAfter(clean)
}
// Only enable publishing task for properly configured projects
val publishingTasks = tasks.withType<PublishToMavenRepository> {
enabled = "ossrhUser" in properties
mustRunAfter(rebuild)
dependsOn(rebuild)
}
tasks.create("release") {
dependsOn(publishingTasks)
afterEvaluate {
// Collect all the publishing task which upload the archives to nexus staging
val closeAndReleaseSonatypeStagingRepository: Task by tasks
// Make sure the close and release happens after uploading
dependsOn(closeAndReleaseSonatypeStagingRepository)
closeAndReleaseSonatypeStagingRepository.mustRunAfter(publishingTasks)
}
}