Skip to content

Commit 469d1b8

Browse files
vizteatopi314
andauthored
Switch to kotlin gradle dsl and use version catalogs (#672)
* Switch to kotlin gradle dsl and version catalogs * Use jetbrains annotations * We don't want tomcat * Add spotbugs * Revert annotation import change Co-authored-by: TopiSenpai <[email protected]>
1 parent 4109155 commit 469d1b8

File tree

11 files changed

+387
-342
lines changed

11 files changed

+387
-342
lines changed

LavalinkServer/build.gradle

Lines changed: 0 additions & 145 deletions
This file was deleted.

LavalinkServer/build.gradle.kts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import org.ajoberstar.grgit.Grgit
2+
import org.apache.tools.ant.filters.ReplaceTokens
3+
import org.springframework.boot.gradle.tasks.bundling.BootJar
4+
import org.springframework.boot.gradle.tasks.run.BootRun
5+
6+
plugins {
7+
application
8+
`maven-publish`
9+
}
10+
11+
apply(plugin = "org.springframework.boot")
12+
apply(plugin = "com.gorylenko.gradle-git-properties")
13+
apply(plugin = "org.ajoberstar.grgit")
14+
apply(plugin = "com.adarshr.test-logger")
15+
apply(plugin = "kotlin")
16+
apply(plugin = "kotlin-spring")
17+
18+
description = "Play audio to discord voice channels"
19+
version = versionFromTag()
20+
21+
application {
22+
mainClass.set("lavalink.server.Launcher")
23+
}
24+
25+
java {
26+
sourceCompatibility = JavaVersion.VERSION_11
27+
targetCompatibility = JavaVersion.VERSION_11
28+
}
29+
30+
configurations {
31+
compileOnly {
32+
extendsFrom(annotationProcessor.get())
33+
}
34+
}
35+
36+
dependencies {
37+
implementation(projects.pluginApi)
38+
39+
implementation(libs.bundles.metrics)
40+
implementation(libs.bundles.spring) {
41+
exclude(group = "org.springframework.boot", module = "spring-boot-starter-tomcat")
42+
}
43+
44+
implementation(libs.koe) {
45+
// This version of SLF4J does not recognise Logback 1.2.3
46+
exclude(group = "org.slf4j", module = "slf4j-api")
47+
}
48+
implementation(libs.koe.udpqueue)
49+
50+
implementation(libs.lavaplayer)
51+
implementation(libs.lavaplayer.ip.rotator)
52+
53+
implementation(libs.lavadsp)
54+
implementation(libs.kotlin.reflect)
55+
implementation(libs.logback)
56+
implementation(libs.sentry.logback)
57+
implementation(libs.oshi)
58+
implementation(libs.json)
59+
implementation(libs.gson)
60+
61+
compileOnly(libs.spotbugs)
62+
63+
testImplementation(libs.spring.boot.test)
64+
}
65+
66+
tasks {
67+
build {
68+
doLast {
69+
println("Version: $version")
70+
}
71+
}
72+
73+
processResources {
74+
val buildNumber = if (System.getenv("CI") != null) {
75+
System.getenv("BUILD_NUMBER") ?: "Unknown"
76+
} else {
77+
"Unofficial"
78+
}
79+
80+
val tokens = mapOf(
81+
"project.version" to project.version,
82+
"project.groupId" to project.group,
83+
"project.artifactId" to "Lavalink-Server",
84+
"env.BUILD_NUMBER" to buildNumber,
85+
"env.BUILD_TIME" to System.currentTimeMillis().toString()
86+
)
87+
88+
filter(ReplaceTokens::class, mapOf("tokens" to tokens))
89+
}
90+
91+
// https://stackoverflow.com/questions/41444916/multiple-artifacts-issue-with-deploying-zip-to-nexus
92+
named<AbstractArchiveTask>("bootDistTar") {
93+
archiveClassifier.set("bootTar")
94+
}
95+
96+
named<AbstractArchiveTask>("bootDistZip") {
97+
archiveClassifier.set("bootZip")
98+
}
99+
100+
named<Test>("test") {
101+
useJUnitPlatform()
102+
}
103+
104+
withType<BootJar> {
105+
archiveFileName.set("Lavalink.jar")
106+
}
107+
108+
withType<BootRun> {
109+
dependsOn("compileTestJava")
110+
111+
//pass in custom jvm args
112+
// source: https://stackoverflow.com/a/25079415
113+
// example: ./gradlew bootRun -PjvmArgs="--illegal-access=debug -Dwhatever=value"
114+
if (project.hasProperty("jvmArgs")) {
115+
val args = project.property("jvmArgs")
116+
.toString()
117+
.split("\\s".toPattern())
118+
119+
jvmArgs?.addAll(args)
120+
}
121+
}
122+
}
123+
124+
@SuppressWarnings("GrMethodMayBeStatic")
125+
fun versionFromTag(): String = Grgit.open(mapOf("currentDir" to project.rootDir)).use { git ->
126+
val headTag = git.tag
127+
.list()
128+
.find { it.commit.id == git.head().id }
129+
130+
val clean = git.status().isClean || System.getenv("CI") != null
131+
if (!clean) {
132+
println("Git state is dirty, setting version as snapshot.")
133+
}
134+
135+
return if (headTag != null && clean) headTag.name else "${git.head().id}-SNAPSHOT"
136+
}
137+
138+
//create a simple version file that we will be reading to create appropriate docker tags
139+
fun versionTxt() {
140+
val versionTxt = File("$projectDir/VERSION.txt")
141+
versionTxt.writeText("${project.version}\n")
142+
}
143+
144+
versionTxt()

Testbot/build.gradle

Lines changed: 0 additions & 28 deletions
This file was deleted.

Testbot/build.gradle.kts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
application
3+
4+
kotlin("jvm")
5+
}
6+
7+
group = "lavalink"
8+
version = "1.0"
9+
10+
application {
11+
mainClass.set("lavalink.testbot.TestbotKt")
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
jcenter()
17+
maven("https://jitpack.io")
18+
}
19+
20+
dependencies {
21+
compileOnly(libs.lavalink.client)
22+
compileOnly(libs.logback)
23+
compileOnly(libs.kotlin.stdlib.jdk8)
24+
compileOnly(libs.jda) {
25+
exclude(module = "opus-java")
26+
}
27+
}

0 commit comments

Comments
 (0)