-
Notifications
You must be signed in to change notification settings - Fork 70
/
build.gradle.kts
179 lines (155 loc) · 5 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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.hangarpublishplugin.model.Platforms
import java.io.ByteArrayOutputStream
val paperVersion: List<String> = (property("gameVersions") as String)
.split(",")
.map { it.trim() }
plugins {
`java-library`
id("com.github.johnrengelman.shadow") version "8.1.1"
// For ingametesting
//id("io.papermc.paperweight.userdev") version "1.5.10"
idea
id("io.papermc.hangar-publish-plugin") version "0.1.2"
}
// Make sure javadocs are available to IDE
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
repositories {
mavenCentral()
// Spigot API
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://oss.sonatype.org/content/repositories/central")
// Placeholder API
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
// CodeMC Repo for bStats
maven("https://repo.codemc.org/repository/maven-public/")
// Auth library from Minecraft
maven("https://libraries.minecraft.net/")
// Protocollib
maven("https://repo.dmulloy2.net/repository/public/")
}
dependencies {
implementation("org.bstats:bstats-bukkit:3.0.2")
// Shaded in by Bukkit
compileOnly("io.netty:netty-all:4.1.106.Final")
// Placeholder API
compileOnly("me.clip:placeholderapi:2.11.5")
// For BSON file serialisation
implementation("org.mongodb:bson:5.0.1")
// Spigot
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
// ProtocolLib
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
//For ingametesting
// Mojang mappings for NMS
/*
compileOnly("com.mojang:authlib:4.0.43")
paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT")
// For reflection remapping
implementation("xyz.jpenilla:reflection-remapper:0.1.1")
*/
}
group = "kernitus.plugin.OldCombatMechanics"
version = "2.0.5-beta" // x-release-please-version
description = "OldCombatMechanics"
java {
toolchain {
// We can build with Java 17 but still support MC >=1.9
// This is because MC >=1.9 server can be run with higher Java versions
languageVersion.set(JavaLanguageVersion.of(17))
}
}
sourceSets {
main {
java {
exclude("kernitus/plugin/OldCombatMechanics/tester/**")
}
}
}
// Substitute ${pluginVersion} in plugin.yml with version defined above
tasks.named<Copy>("processResources") {
inputs.property("pluginVersion", version)
filesMatching("plugin.yml") {
expand("pluginVersion" to version)
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.named<ShadowJar>("shadowJar") {
dependsOn("jar")
archiveFileName.set("${project.name}.jar")
dependencies {
relocate("org.bstats", "kernitus.plugin.OldCombatMechanics.lib.bstats")
}
}
// For ingametesting
/*
tasks.reobfJar {
outputJar.set(File(buildDir, "libs/${project.name}.jar"))
}
*/
tasks.assemble {
// For ingametesting
//dependsOn("reobfJar")
dependsOn("shadowJar")
}
// Function to execute Git commands
fun executeGitCommand(vararg command: String): String {
val byteOut = ByteArrayOutputStream()
project.exec {
commandLine = listOf("git", *command)
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
// Function to get the latest commit message
fun latestCommitMessage(): String {
return executeGitCommand("log", "-1", "--pretty=%B")
}
// Function to get the short commit hash
fun getShortCommitHash(): String {
return executeGitCommand("rev-parse", "--short", "HEAD")
}
val versionString: String = project.version as String
val isRelease: Boolean = !versionString.contains('-')
val suffixedVersion: String = if (isRelease) {
versionString
} else {
// Append the short commit hash to the version for snapshots
"$versionString+${getShortCommitHash()}"
}
// Use the latest commit message for the changelog
val changelogContent: String = latestCommitMessage()
tasks.register("printIsRelease") {
doLast {
val isRelease = !project.version.toString().contains('-')
println(if (isRelease) "true" else "false")
}
}
hangarPublish {
publications.register("plugin") {
version.set(suffixedVersion)
channel.set(if (isRelease) "Release" else "Snapshot")
id.set("OldCombatMechanics")
apiKey.set(System.getenv("HANGAR_API_TOKEN"))
changelog.set(System.getenv("HANGAR_CHANGELOG") ?: changelogContent)
platforms {
register(Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(paperVersion)
}
}
}
}