-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.gradle.kts
271 lines (208 loc) · 6.45 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-base:1.+")
}
dependencyLocking.lockAllConfigurations()
}
plugins {
`maven-publish`
signing
kotlin("jvm") version "2.0.0"
id("io.github.gradle-nexus.publish-plugin") version "1.+"
id("io.gitlab.arturbosch.detekt") version "1.+"
id("org.jetbrains.dokka") version "1.+"
}
group = "club.minnced"
version = "0.12.0"
val jdaVersion = "5.0.0"
////////////////////////////////
// Dependency Version Locking //
////////////////////////////////
fun ComponentSelectionRules.notRc() {
all {
if (candidate.version.contains("RC", ignoreCase = true))
reject("not a release version")
}
}
// To update lockfile, run ./gradlew dependencies --update-locks '<group id>:<artifact id>'
// To update all locks use ./gradlew dependencies --write-locks
configurations {
compileClasspath {
resolutionStrategy.activateDependencyLocking()
resolutionStrategy.componentSelection.notRc()
}
runtimeClasspath {
resolutionStrategy.activateDependencyLocking()
resolutionStrategy.componentSelection.notRc()
}
}
dependencyLocking {
lockMode.set(LockMode.STRICT)
}
///////////////////////////
// Compile Configuration //
///////////////////////////
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile> {
kotlinOptions.allWarningsAsErrors = true
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf(
"-Xjvm-default=all", // use default methods in interfaces
)
}
////////////////////////////
// Dependency Declaration //
////////////////////////////
repositories {
mavenCentral()
}
dependencies {
compileOnly("ch.qos.logback:logback-classic:latest.release")
compileOnly("club.minnced:discord-webhooks:latest.release")
api(kotlin("stdlib"))
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.+")
implementation("net.dv8tion:JDA:$jdaVersion")
}
////////////////////////
// Task Configuration //
////////////////////////
val javadoc: Javadoc by tasks
val sourcesJar = task<Jar>("sourcesJar") {
from(sourceSets["main"].allSource)
archiveClassifier.set("sources")
}
val javadocJar = task<Jar>("javadocJar") {
from(javadoc.destinationDir)
archiveClassifier.set("javadoc")
dependsOn(javadoc)
}
tasks {
build {
dependsOn(javadocJar)
dependsOn(sourcesJar)
dependsOn(jar)
}
}
/////////////
// Linting //
/////////////
detekt {
parallel = true
autoCorrect = false
config.from(files("detekt.yml"))
}
tasks.test.get().dependsOn(tasks.getByName("detekt"))
///////////////////
// Documentation //
///////////////////
tasks.getByName("dokkaHtml", DokkaTask::class) {
dokkaSourceSets.configureEach {
includes.from("packages.md")
jdkVersion.set(8)
sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(URI("https://github.com/MinnDevelopment/jda-ktx/tree/master/src/main/kotlin").toURL())
remoteLineSuffix.set("#L")
}
externalDocumentationLink(
URI("https://ci.dv8tion.net/job/JDA5/javadoc/").toURL(),
URI("https://ci.dv8tion.net/job/JDA5/javadoc/element-list").toURL()
)
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
footerMessage = "Copyright © 2020 Florian Spieß"
}
}
}
////////////////
// Publishing //
////////////////
// Generate pom file for maven central
fun generatePom(): MavenPom.() -> Unit {
return {
packaging = "jar"
name.set(project.name)
description.set("Collection of useful Kotlin extensions for JDA")
url.set("https://github.com/MinnDevelopment/jda-ktx")
scm {
url.set("https://github.com/MinnDevelopment/jda-ktx")
connection.set("scm:git:git://github.com/MinnDevelopment/jda-ktx")
developerConnection.set("scm:git:ssh:[email protected]:MinnDevelopment/jda-ktx")
}
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]")
}
}
}
}
publishing.publications {
register<MavenPublication>("Release") {
from(components["java"])
artifactId = project.name
groupId = project.group as String
version = project.version as String
artifact(javadocJar)
artifact(sourcesJar)
pom.apply(generatePom())
// Uses the resolved version instead of the 1.+ wildcards
// See https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:resolved_dependencies
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
}
}
val signingKey: String? by project
val signingKeyId: String? by project
val ossrhUser: String? by project
val ossrhPassword: String? by project
val stagingProfile: String? by project
val enablePublishing = ossrhUser != null && ossrhPassword != null && stagingProfile != null
signing {
useInMemoryPgpKeys(signingKeyId, signingKey, "")
sign(*publishing.publications.toTypedArray())
isRequired = enablePublishing
}
if (enablePublishing) {
nexusPublishing {
repositories.sonatype {
username.set(ossrhUser)
password.set(ossrhPassword)
stagingProfileId.set(stagingProfile)
}
}
}
val build by tasks
val clean by tasks
build.mustRunAfter(clean)
val rebuild = tasks.register<Task>("rebuild") {
group = "build"
dependsOn(clean, build)
}
// Only enable publishing task for properly configured projects
val publishingTasks = tasks.withType<PublishToMavenRepository> {
enabled = ossrhUser?.isNotEmpty() == true
mustRunAfter(rebuild)
dependsOn(rebuild)
}