forked from bitmochibit/Defcon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
247 lines (206 loc) · 7.22 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
247 lines (206 loc) · 7.22 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
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
import net.minecrell.pluginyml.paper.PaperPluginDescription
import java.time.Instant
// Dependency versions - centralized for easier management
object Versions {
const val KOTLIN = "2.1.20"
const val KOTLINX_COROUTINES = "1.10.2"
const val KTOR = "3.1.2"
const val PAPER_API = "1.21.4-R0.1-SNAPSHOT"
const val PACKET_EVENTS = "2.7.0"
const val CUSTOM_BLOCK_DATA = "2.2.4"
const val GSON = "2.10.1"
const val JUNIT = "5.10.1"
const val MOCKITO = "5.8.0"
const val JVM = 21
const val MOCKBUKKIT = "4.0.0"
const val MCCOROUTINE = "2.22.0"
val JAVA_VERSION = JavaVersion.VERSION_21
}
plugins {
kotlin("jvm") version "2.1.20"
id("com.gradleup.shadow") version "9.0.0-beta12"
id("xyz.jpenilla.run-paper") version "2.3.1"
id("de.eldoria.plugin-yml.bukkit") version "0.7.1"
}
group = "me.mochibit"
version = "1.3.5a-SNAPSHOT"
// Project metadata
description = "A plugin that adds nuclear energy, along with its advantages and dangers"
object PacketEvents {
const val PLATFORM = "spigot"
}
// Output configuration
val outputPluginDirectory: String = project.findProperty("outputDir")?.toString()
?: layout.buildDirectory.dir("libs").get().asFile.path
logger.lifecycle("Output directory: $outputPluginDirectory")
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(Versions.JVM))
}
}
// Java configuration
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(Versions.JVM))
}
withSourcesJar()
withJavadocJar()
sourceCompatibility = Versions.JAVA_VERSION
targetCompatibility = Versions.JAVA_VERSION
}
// Plugin.yml generation
bukkit {
main = "me.mochibit.defcon.Defcon"
apiVersion = "1.21"
name = "Defcon"
version = project.version.toString()
description = project.description
authors = listOf("MochiBit")
website = "https://github.com/mochibit/defcon"
// loader = "me.mochibit.defcon.plugin.loader.DefconLoader"
// generateLibrariesJson = true
// serverDependencies {
// register("packetevents") {
// load = PaperPluginDescription.RelativeLoadOrder.BEFORE
// required = true
// }
// }
depend = listOf("packetevents")
permissions {
register("defcon.admin") {
description = "Gives access to all Defcon admin commands"
default = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.Permission.Default.OP
}
}
}
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/") {
name = "papermc-repo"
}
maven("https://oss.sonatype.org/content/groups/public/") {
name = "sonatype"
}
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/") // CustomBlockData
maven { url = uri("https://repo.codemc.io/repository/maven-releases/") }
maven { url = uri("https://repo.codemc.io/repository/maven-snapshots/") }
}
dependencies {
// Server API - compileOnly to avoid bundling
compileOnly("io.papermc.paper:paper-api:${Versions.PAPER_API}")
compileOnly("com.github.retrooper", "packetevents-${PacketEvents.PLATFORM}", Versions.PACKET_EVENTS)
// Libraries to be shaded
implementation("com.jeff-media:custom-block-data:${Versions.CUSTOM_BLOCK_DATA}")
// Reflection api
implementation("org.reflections:reflections:0.10.2") {
exclude(group = "org.slf4j")
exclude(group = "com.google.code.findbugs")
}
library("org.jetbrains.kotlinx", "kotlinx-coroutines-core", Versions.KOTLINX_COROUTINES)
// Coroutines
library("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-api", Versions.MCCOROUTINE)
library("com.github.shynixn.mccoroutine", "mccoroutine-bukkit-core", Versions.MCCOROUTINE)
library(kotlin("stdlib", Versions.KOTLIN))
library(kotlin("reflect", Versions.KOTLIN))
library("com.google.code.gson:gson:${Versions.GSON}")
// Testing
testImplementation(kotlin("test", Versions.KOTLIN))
testImplementation("org.junit.jupiter:junit-jupiter:${Versions.JUNIT}")
testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:${Versions.MOCKBUKKIT}")
testImplementation("org.mockito:mockito-core:${Versions.MOCKITO}")
testImplementation("io.papermc.paper:paper-api:${Versions.PAPER_API}")
}
// Kotlin compilation
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget(Versions.JVM.toString()))
freeCompilerArgs.addAll("-Xjvm-default=all", "-opt-in=kotlin.RequiresOptIn")
}
}
// Java compilation
tasks.withType<JavaCompile>().configureEach {
options.apply {
encoding = "UTF-8"
release.set(Versions.JVM)
}
}
// Testing configuration
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
// Parallel test execution for faster builds
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
}
// Server test configuration
tasks.runServer {
minecraftVersion("1.20.2")
downloadPlugins {
github(
"retrooper",
"packetevents",
"v${Versions.PACKET_EVENTS}",
"packetevents-${PacketEvents.PLATFORM}-${Versions.PACKET_EVENTS}.jar"
)
}
}
// JAR configuration
tasks.jar {
archiveBaseName.set("Defcon")
archiveVersion.set(project.version.toString())
enabled = false // Disable default jar
}
// Shadow JAR configuration
tasks.shadowJar {
archiveBaseName.set("Defcon")
archiveFileName.set("Defcon-${version}.jar")
archiveClassifier.set("")
archiveVersion.set(project.version.toString())
// Relocate dependencies
relocate("com.jeff_media.customblockdata", "me.mochibit.lib.customblockdata")
// Minimize JAR size
minimize {
exclude(dependency("org.jetbrains.kotlin:.*"))
exclude(dependency("org.jetbrains.kotlinx:.*"))
}
// Exclude unnecessary files
exclude("META-INF/*.DSA", "META-INF/*.RSA", "META-INF/*.SF")
// Add build timestamp manifest entry
manifest {
attributes(
"Built-By" to System.getProperty("user.name"),
"Build-Timestamp" to Instant.now().toString(),
"Created-By" to "Gradle ${gradle.gradleVersion}",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version
)
}
}
// Default artifact
artifacts {
archives(tasks.shadowJar)
}
// Make shadowJar part of the build process
tasks.build {
dependsOn(tasks.shadowJar)
}
// Install plugin task
tasks.register<Copy>("installPlugin") {
dependsOn(tasks.shadowJar)
from(tasks.shadowJar.get().archiveFile)
into(file(outputPluginDirectory))
doLast {
logger.lifecycle("Plugin installed to: $outputPluginDirectory/${tasks.shadowJar.get().archiveFileName.get()}")
}
}
// Clean, build and install task
tasks.register("cleanBuildInstall") {
group = "build"
description = "Cleans the project, builds it, and installs the plugin to the output directory"
dependsOn(tasks.clean, "installPlugin")
}
// Configure Gradle to use parallel execution where possible
gradle.taskGraph.whenReady {
System.setProperty("org.gradle.parallel", "true")
}