-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
261 lines (222 loc) · 7.32 KB
/
build.gradle
File metadata and controls
261 lines (222 loc) · 7.32 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id 'java'
id "xyz.jpenilla.run-paper" version "2.3.1"
id "com.gradleup.shadow" version "8.3.6"
}
def IS_WORKFLOW = project.hasProperty('Workflow')
def LUAJAVA_DIR = project.layout.projectDirectory.dir("luajava").asFile
ext.targetJavaVersion = 8
if (project.hasProperty('TargetJava')) {
ext.targetJavaVersion = Integer.parseInt(project.property('TargetJava').toString())
}
if (project.targetJavaVersion <= 8) {
execCommand("git apply ../patchs/luajava-java8.patch", LUAJAVA_DIR)
}
execCommand("git apply ../patchs/luajava-gradle.patch", LUAJAVA_DIR)
ext.gitHash = getGitHash(project.rootDir)
ext.gitBranch = execCommand("git rev-parse --abbrev-ref HEAD", project.rootDir)
ext.gitTag = getGitTag(project.rootDir)
ext.gitVersion = project.gitTag == null ?
"${project.gitBranch}-${project.gitHash}" : "${project.gitTag}"
ext.gitHashLuajava = getGitHash(LUAJAVA_DIR)
ext.gitBranchLuajava = execCommand("git rev-parse --abbrev-ref HEAD", LUAJAVA_DIR)
ext.gitTagLuajava = getGitTag(LUAJAVA_DIR)
ext.luajavaVersion = project.gitTagLuajava == null ?
"${project.gitBranchLuajava}-${project.gitHashLuajava}" : "${project.gitTagLuajava}"
ext.apiPath = "org/eu/smileyik/luaInMinecraftBukkitII/api/**"
group = 'org.eu.smileyik'
version = project.gitTag == null ?
"${project.gitVersion}+luajava-${project.luajavaVersion}+java-${project.targetJavaVersion}" :
"${project.gitVersion}"
if (gradle.foliaSupport) version += "+folia"
repositories {
mavenCentral()
maven {
name = "spigotmc-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
if (IS_WORKFLOW) {
maven {
url "https://raw.githubusercontent.com/SmileYik/LuaInMinecraftBukkitII/refs/heads/gh-page/repo"
}
} else {
maven {
url "https://maven-v4.smileyik.eu.org:60081/public"
}
maven {
url "https://maven.smileyik.eu.org:60081/public"
}
}
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
annotationProcessor 'org.jetbrains:annotations:24.0.0'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
compileOnly 'org.jetbrains:annotations:24.0.0'
compileOnly 'org.projectlombok:lombok:1.18.30'
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
testImplementation("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
implementation project(":luajava:java")
// command
implementation("org.eu.smileyik:SimpleCommand:1.0.7-SNAPSHOT")
// SimpleDebug
implementation 'org.eu.smileyik:SimpleDebug:1.0.2-SNAPSHOT'
// byte buddy
implementation 'net.bytebuddy:byte-buddy:1.14.3'
// bstats
implementation 'org.bstats:bstats-bukkit:3.0.2'
// scheduler
implementation project(":scheduler")
if (gradle.foliaSupport) {
implementation project(":scheduler:scheduler-folia")
}
}
tasks {
runServer {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion("1.21.5")
}
}
test {
useJUnitPlatform()
}
def targetJavaVersion = ext.targetJavaVersion
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
}
}
processResources {
def props = [
version: version,
foliaSupported: gradle.foliaSupport
]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}
classes {
// restore patch
doLast {
generateResourceList(layout.buildDirectory.dir("resources/main/resources").get())
exec {
workingDir layout.projectDirectory.dir("luajava")
commandLine 'git', 'restore', '*'
}
}
}
shadowJar {
relocate 'org.eu.smileyik.simpledebug', 'org.eu.smileyik.luaInMinecraftBukkitII.simpledebug'
relocate 'org.eu.smileyik.simplecommand', 'org.eu.smileyik.luaInMinecraftBukkitII.simplecommand'
relocate 'net.bytebuddy', 'org.eu.smileyik.luaInMinecraftBukkitII.bytebuddy'
relocate 'org.bstats', 'org.eu.smileyik.luaInMinecraftBukkitII.bstats'
manifest {
attributes 'Build-Timestamp': System.currentTimeMillis()
}
}
javadoc {
failOnError false
options {
encoding 'UTF-8'
charSet 'UTF-8'
author true
version true
}
}
tasks.register('sourcesJar', Jar) {
group = "custom jar"
dependsOn classes
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
tasks.register("javadocJar", Jar) {
group = "custom jar"
dependsOn javadoc
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
tasks.register("apiJavadoc", Javadoc) {
destinationDir file("${destinationDir}/../api-javadoc/")
failOnError false
options {
encoding 'UTF-8'
charSet 'UTF-8'
author true
version true
}
source = sourceSets.main.allJava
include project.apiPath
}
tasks.register("apiJar", ShadowJar) {
group = "custom jar"
description = "Create Jar file just include api"
archiveClassifier = "api"
from sourceSets.main.output
include project.apiPath
}
tasks.register("apiJavadocJar", ShadowJar) {
group = "custom jar"
dependsOn apiJavadoc
description = "Create a Javadoc for api Jar"
archiveClassifier = "api-javadoc"
from apiJavadoc.destinationDir
}
tasks.register("apiSourcesJar", ShadowJar) {
group = "custom jar"
description = "Create a Javadoc for api Jar"
archiveClassifier = "api-sources"
from sourceSets.main.allSource
include project.apiPath
}
build {
dependsOn apiJar, apiJavadocJar, apiSourcesJar, javadocJar, sourcesJar, shadowJar
}
static def execCommand(command, dir) {
def output = "unknown"
try {
def process = command.execute(null, dir)
process.waitFor()
if (process.exitValue() == 0) {
output = process.text.trim()
}
} catch (Exception ignore) {
}
return output
}
static def getGitTag(dir) {
def tag = execCommand("git describe --tags --exact-match", dir)
return tag == "unknown" ? null : tag
}
static def getGitHash(dir) {
def hash = execCommand("git rev-parse HEAD", dir)
return hash == "unknown" ? hash : hash.substring(0, 7)
}
static def generateResourceList(Directory dir) {
dir.asFile.listFiles()?.findAll { it.isDirectory() }?.each {
def parent = dir.dir(it.name)
def prefixLength = "$parent".length() + 1
def list = parent.asFileTree.collect {
it.toString().substring(prefixLength)
}
dir.file(it.name + ".list").asFile.write(list.join("\n"))
}
}