-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle.kts
254 lines (211 loc) · 6.9 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
@file:Suppress("UnstableApiUsage")
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.apache.tools.ant.filters.ReplaceTokens
import org.ajoberstar.grgit.Grgit
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import java.time.LocalDate
plugins {
java
`java-library`
`maven-publish`
kotlin("jvm") version libs.versions.kotlin
kotlin("plugin.serialization") version libs.versions.kotlin
id("org.jetbrains.dokka") version libs.versions.dokka
id("org.ajoberstar.grgit") version libs.versions.grgit
id("com.vanniktech.maven.publish.base") version libs.versions.maven.publish
}
buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-base:${libs.versions.dokka.get()}")
}
}
val (gitVersion, release) = versionFromGit()
logger.lifecycle("Version: $gitVersion (release: $release)")
group = "dev.arbjerg"
version = gitVersion
val archivesBaseName = "lavalink-client"
allprojects {
repositories {
mavenCentral()
maven("https://maven.lavalink.dev/releases")
maven("https://maven.lavalink.dev/snapshots")
maven("https://maven.topi.wtf/releases")
// Note to self: jitpack always comes last
maven("https://jitpack.io")
}
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
dependencies {
// package libraries
api(kotlin("stdlib"))
// api(libs.kotlin)
api(libs.lavalink.protocol)
api(libs.okhttp)
api(libs.jackson)
api(libs.bundles.reactor)
api(libs.logger.api)
// Discord library support
compileOnly(libs.jda)
compileOnly(libs.d4j)
testImplementation(kotlin("test"))
testImplementation(libs.jda)
testImplementation(libs.d4j)
testImplementation(libs.logger.impl)
testImplementation(libs.lyrics)
testImplementation(libs.lavasearch)
}
tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
val sourcesForRelease = task<Copy>("sourcesForRelease") {
from("src/main/kotlin") {
include("**/LLClientInfo.kt.txt")
filter<ReplaceTokens>(mapOf("tokens" to mapOf(
"VERSION" to project.version
)))
rename("LLClientInfo.kt.txt", "LLClientInfo.kt")
}
into("build/filteredSrc")
includeEmptyDirs = false
}
val generateKotlinSources = task<SourceTask>("generateKotlinSources") {
val javaSources = sourceSets["main"].allSource.filter {
it.name != "LLClientInfo.kt"
}.asFileTree
source = javaSources + fileTree(sourcesForRelease.destinationDir)
dependsOn(sourcesForRelease)
}
val sourcesJar = task<Jar>("sourcesJar") {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:deprecation")
}
tasks.compileKotlin {
source(generateKotlinSources.source)
dependsOn(generateKotlinSources)
}
tasks.build {
dependsOn(tasks.dokkaJavadoc)
}
tasks.test {
useJUnitPlatform()
}
tasks.wrapper {
gradleVersion = "8.5"
distributionType = Wrapper.DistributionType.BIN
}
tasks.withType<Sign> {
dependsOn(sourcesJar)
dependsOn(tasks.kotlinSourcesJar)
}
tasks.withType<PublishToMavenRepository> {
dependsOn(sourcesJar)
dependsOn(tasks.kotlinSourcesJar)
}
kotlin {
jvmToolchain(17)
}
tasks.withType<DokkaTask>().configureEach {
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
customAssets = listOf(file("dokka/assets/logo-icon.svg"))
footerMessage = "© ${LocalDate.now().year} Lavalink devs<br />Licensed under the MIT license"
separateInheritedMembers = false
}
}
val mavenUrl: String
get() {
if (release) {
return "https://maven.lavalink.dev/releases"
}
return "https://maven.lavalink.dev/snapshots"
}
publishing {
repositories {
maven {
name = "arbjerg"
url = uri(mavenUrl)
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
authentication {
create<BasicAuthentication>("basic")
}
}
}
}
mavenPublishing {
configure(KotlinJvm(
javadocJar = JavadocJar.Dokka("dokkaJavadoc"),
sourcesJar = true
))
}
afterEvaluate {
plugins.withId("com.vanniktech.maven.publish.base") {
configure<MavenPublishBaseExtension> {
coordinates(group.toString(), project.the<BasePluginExtension>().archivesName.get(), version.toString())
if (findProperty("mavenCentralUsername") != null && findProperty("mavenCentralPassword") != null) {
publishToMavenCentral(SonatypeHost.S01, false)
if (release) {
signAllPublications()
}
} else {
logger.lifecycle("Not publishing to OSSRH due to missing credentials")
}
pom {
name.set(archivesBaseName)
description.set("Lavalink v4 client library")
url.set("https://github.com/lavalink-devs/lavalink-client")
licenses {
license {
name.set("MIT")
url.set("https://github.com/lavalink-devs/lavalink-client/blob/main/LICENSE")
}
}
developers {
developer {
id.set("duncte123")
name.set("Duncan Sterken")
url.set("https://duncte123.dev/")
}
}
scm {
url.set("https://github.com/lavalink-devs/lavalink-client")
connection.set("scm:git:git://github.com/lavalink-devs/lavalink-client.git")
developerConnection.set("scm:git:ssh://git@github.com:lavalink-devs/lavalink-client.git")
}
}
}
}
}
val publish: Task by tasks
publish.apply {
dependsOn(tasks.build)
onlyIf {
System.getenv("MAVEN_USERNAME") != null && System.getenv("MAVEN_PASSWORD") != null
}
}
fun versionFromGit(): Pair<String, Boolean> {
Grgit.open(mapOf("currentDir" to project.rootDir)).use { git ->
val headTag = git.tag
.list()
.find { it.commit.id == git.head().id }
val clean = git.status().isClean || System.getenv("CI") != null
if (!clean) {
logger.lifecycle("Git state is dirty, version is a snapshot.")
}
return if (headTag != null && clean) headTag.name to true else "${git.head().id}-SNAPSHOT" to false
}
}