generated from lavalink-devs/lavalink-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
92 lines (79 loc) · 2.32 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
import java.io.ByteArrayOutputStream
import java.net.URI
plugins {
java
`maven-publish`
alias(libs.plugins.lavalink)
}
group = "dev.arbjerg.test.plugin"
val (versionStr, isSnapshot) = getGitVersion()
version = versionStr
println("Version: $versionStr")
lavalinkPlugin {
name = "test-plugin"
apiVersion = libs.versions.lavalink.api
serverVersion = gitHash(libs.versions.lavalink.server)
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks {
compileJava {
options.encoding = "UTF-8"
}
}
val isMavenDefined = findProperty("MAVEN_USERNAME") != null && findProperty("MAVEN_PASSWORD") != null
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
if (isMavenDefined) {
println("Publishing to Maven Repo")
repositories {
val snapshots = "https://maven.arbjerg.dev/snapshots"
val releases = "https://maven.arbjerg.dev/releases"
maven {
name = "Reposilite"
url = URI(if (isSnapshot) snapshots else releases)
credentials {
username = findProperty("MAVEN_USERNAME") as String
password = findProperty("MAVEN_PASSWORD") as String
}
}
}
} else {
println("Maven credentials not found, not publishing to Maven Repo")
}
}
fun getGitVersion(): Pair<String, Boolean> {
var versionStr = ByteArrayOutputStream()
var result = exec {
standardOutput = versionStr
isIgnoreExitValue = true
commandLine = listOf("git", "describe", "--exact-match", "--tags")
}
if (result.exitValue == 0) {
return Pair(versionStr.toString().trim(), false)
}
versionStr = ByteArrayOutputStream()
result = exec {
standardOutput = versionStr
isIgnoreExitValue = true
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
}
if (result.exitValue != 0) {
throw GradleException("Failed to get git version")
}
return Pair(versionStr.toString().trim(), true)
}
fun getCommitHash(): String {
val p = Runtime.getRuntime().exec("git rev-parse HEAD")
p.waitFor()
p.inputStream.bufferedReader().use {
return it.readText().trim()
}
}