forked from ProtocolSupport/ProtocolSupport
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
203 lines (168 loc) · 6.56 KB
/
build.gradle
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
plugins {
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'java'
}
apply from: 'helper.gradle'
defaultTasks 'build'
group 'protocolsupport'
version '4.29-dev-pe'
sourceCompatibility = JavaVersion.VERSION_1_8
File librariesRuntimeDirectory = new File("libraries_runtime")
File librariesShadeDirectory = new File("libraries_shade")
File generatedResourcesDirectory = new File("gen")
File annotationProcessorsDirectory = new File("processors")
File targetJarDirectory = new File("target")
String resourcesDirectoryName = "resources";
task setupFolders(type: DefaultTask) {doLast{
librariesRuntimeDirectory.mkdirs()
librariesShadeDirectory.mkdirs()
targetJarDirectory.mkdirs()
generatedResourcesDirectory.deleteDir()
generatedResourcesDirectory.mkdirs()
}}
task updateSpigot(type: BuildLibraryTask) {
targetDirectory = librariesRuntimeDirectory
targetLibraryName = "spigot-1.14.3-1.jar"
builderUrl = "https://papermc.io/api/v1/paper/1.14.3/108/download"
buildCommand = "java -Dpaperclip.patchonly=true -jar {BUILDER}"
builtLibraryName = ["cache", "patched_1.14.3.jar"]
}
task updateRuntimeLibraries(type: UpdateLibrariesTask) {
directory = librariesRuntimeDirectory
libraries = []
manualLibraries = new HashSet<>(Arrays.asList(updateSpigot.targetLibraryName))
}
task updateShadeLibraries(type: UpdateLibrariesTask) {
directory = librariesShadeDirectory
libraries = [
[name: 'raknetserver-30.jar', url: 'https://build.true-games.org/job/RakNetServer/30/artifact/target/RakNetServer.jar'],
[name: 'udpserver-11.jar', url: 'https://build.true-games.org/job/UdpServerSocketChannel/11/artifact/target/UdpServerSocketChannel.jar']
]
}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['resources']
}
}
test {
java {
srcDirs = ['tests']
}
}
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.2'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '5.2'
compile fileTree(dir: librariesShadeDirectory, include: '*.jar')
shadow fileTree(dir: librariesRuntimeDirectory, include: '*.jar')
shadow fileTree(dir: new File("libraries_runtime_manual"), include: '*.jar')
annotationProcessor fileTree(dir: annotationProcessorsDirectory, include: '*.jar')
shadow fileTree(dir: annotationProcessorsDirectory, include: '*.jar')
testCompile fileTree(dir: librariesRuntimeDirectory, include: '*.jar')
testCompile fileTree(dir: librariesShadeDirectory, include: '*.jar')
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
}
compileJava {
doFirst {
classpath -= configurations.shadow
classpath += configurations.shadow
}
options.encoding = 'UTF-8'
options.incremental = false
options.compilerArgs << ("-Aprotocolsupportbuildprocessor.generatedresourcesdirectory=" + newFile(generatedResourcesDirectory, resourcesDirectoryName, "preload").getAbsolutePath())
}
test {
useJUnitPlatform()
}
task generateLocaleList(type: DefaultTask) {doLast{
File langsListFile = newFile(generatedResourcesDirectory, resourcesDirectoryName, "i18n", "languages")
langsListFile.getParentFile().mkdirs()
langsListFile.createNewFile()
new PrintWriter(langsListFile).withCloseable({
writer ->
newFile(sourceSets.main.resources.srcDirs.iterator().next(), resourcesDirectoryName, "i18n").list()
.each({
String[] split = it.split("[.]");
if (split.length == 2 && split[1].equals("json")) {
writer.println(split[0])
}
})
})
}}
task generateInfo(type: DefaultTask) {doLast{
Properties properties = new Properties()
properties.setProperty("buildtime", new Date().format("yyyy.MM.dd 'at' HH:mm:ss z"))
properties.setProperty("buildhost", System.getProperty("protocolsupport.buildhost", "unknown"))
properties.setProperty("buildnumber", System.getProperty("protocolsupport.buildnumber", "unknown"))
properties.setProperty("buildgit", System.getProperty("protocolsupport.buildgit", "unknown"))
File buildInfoFile = newFile(generatedResourcesDirectory, resourcesDirectoryName, "buildinfo")
buildInfoFile.getParentFile().mkdirs()
buildInfoFile.createNewFile()
new FileOutputStream(buildInfoFile).withCloseable({ properties.store(it, "Build info") })
}}
shadowJar {
doFirst {
new File(destinationDir, archiveName).delete()
}
from sourceSets.main.java.srcDirs
from 'LICENSE'
from generatedResourcesDirectory
archiveName = jar.archiveName
exclude 'META-INF/**'
relocate 'org.apache', 'protocolsupport.libs.org.apache'
relocate 'it.unimi.dsi.fastutil', 'protocolsupport.libs.it.unimi.dsi.fastutil'
relocate 'com.google.gson', 'protocolsupport.libs.com.google.gson'
relocate 'com.nimbusds', 'protocolsupport.libs.com.nimbusds'
relocate 'org.objectweb', 'protocolsupport.libs.org.objectweb'
relocate 'net.minidev', 'protocolsupport.libs.net.minidev'
relocate 'net.jcip', 'protocolsupport.libs.net.jcip'
relocate 'raknetserver', 'protocolsupport.libs.raknetserver'
relocate 'udpserversocketchannel', 'protocolsupport.libs.udpserversocketchannel'
minimize()
}
task postprocessFatJar(type: Zip) {
Set<String> workaroundRelocationClasses = new HashSet<>(Arrays.asList(
"protocolsupport/zplatform/impl/spigot/entitytracker/SpigotEntityTrackerEntryInjectorMap.class",
"protocolsupport/zplatform/impl/spigot/entitytracker/PaperSpigotEntityTrackerEntryInjectorMap.class",
"protocolsupport/zplatform/impl/spigot/injector/SpigotEntityTrackerInjector.class"
));
File originalJar = new File(shadowJar.destinationDir, shadowJar.archiveName)
archiveName = shadowJar.archiveName
from(zipTree(originalJar)) {
exclude(workaroundRelocationClasses)
exclude 'META-INF/**'
}
from(sourceSets.main.output.classesDirs) {
include(workaroundRelocationClasses)
}
}
task copyFinalJarToTarget(type: DefaultTask) {doLast{
java.nio.file.Files.copy(
postprocessFatJar.archivePath.getAbsoluteFile().toPath(),
new File(targetJarDirectory, jar.baseName + '.jar').getAbsoluteFile().toPath(),
java.nio.file.StandardCopyOption.REPLACE_EXISTING
)
}}
compileJava.dependsOn(clean)
compileJava.dependsOn(setupFolders)
compileJava.dependsOn(updateSpigot)
compileJava.dependsOn(updateRuntimeLibraries)
compileJava.dependsOn(updateShadeLibraries)
compileJava.finalizedBy(test)
jar.enabled = false
jar.finalizedBy(shadowJar)
shadowJar.dependsOn(generateInfo)
shadowJar.dependsOn(generateLocaleList)
shadowJar.finalizedBy(postprocessFatJar)
postprocessFatJar.finalizedBy(copyFinalJarToTarget)