This repository was archived by the owner on Nov 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
148 lines (122 loc) · 3.74 KB
/
build.gradle.kts
File metadata and controls
148 lines (122 loc) · 3.74 KB
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
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
plugins {
`maven-publish`
kotlin("jvm") version "2.1.21"
kotlin("plugin.serialization") version "2.1.21"
application
}
group = "io.github.dockyardmc"
version = "3.2"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
testImplementation("net.kyori:adventure-api:4.21.0")
testImplementation("net.kyori:adventure-text-minimessage:4.21.0")
compileOnly("net.kyori:adventure-api:4.21.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")
implementation("com.google.code.gson:gson:2.13.1")
implementation("net.kyori:adventure-nbt:4.21.0")
}
tasks.withType<Test> {
useJUnitPlatform()
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(21))
})
}
tasks.withType<PublishToMavenRepository> {
dependsOn("test")
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "21"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "21"
}
compileJava {
targetCompatibility = "21"
}
compileTestJava {
targetCompatibility = "21"
}
}
application {
mainClass.set("MainKt")
}
sourceSets["main"].resources.srcDir("${buildDir}/generated/resources/")
sourceSets["main"].java.srcDir("src/main/kotlin")
java {
withSourcesJar()
withJavadocJar()
}
publishing {
repositories {
maven {
url = uri("https://mvn.devos.one/releases")
credentials {
username = System.getenv()["MAVEN_USER"]
password = System.getenv()["MAVEN_PASS"]
}
}
}
publications {
register<MavenPublication>("maven") {
groupId = "io.github.dockyardmc"
artifactId = "scroll"
version = version
from(components["java"])
}
}
}
tasks.publish {
finalizedBy("sendPublishWebhook")
}
task("sendPublishWebhook") {
group = "publishing"
description = "Sends a webhook message after publishing to Maven."
doLast {
sendWebhookToDiscord(System.getenv("DISCORD_DOCKYARD_WEBHOOK"))
}
}
fun sendWebhookToDiscord(webhookUrl: String) {
val httpClient = HttpClient.newHttpClient()
val requestBody = embed()
val request = HttpRequest.newBuilder()
.uri(URI(webhookUrl))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build()
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenRun { println("Webhook sent successfully!") }
.exceptionally { throwable ->
throwable.printStackTrace()
null
}
}
fun embed(): String {
val target = if(version.toString().endsWith("-SNAPSHOT")) "https://mvn.devos.one/snapshots" else "https://mvn.devos.one/releases"
val color = if(version.toString().endsWith("-SNAPSHOT")) 16742912 else 65290
val title = if(version.toString().endsWith("-SNAPSHOT")) "Snapshot Published to Maven" else "Published to Maven"
return """
{
"content": null,
"embeds": [
{
"title": "$title",
"description": "`io.github.dockyardmc:scroll:$version` was successfully published to maven **$target**!",
"color": $color
}
],
"username": "Mavenboo",
"avatar_url": "https://ae01.alicdn.com/kf/Sa4eadafccb024c72a386eff7dfac2c61n.jpg",
"attachments": []
}
""".trimIndent()
}