-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild.gradle
More file actions
243 lines (214 loc) · 8.99 KB
/
Copy pathbuild.gradle
File metadata and controls
243 lines (214 loc) · 8.99 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
import org.gradle.api.tasks.compile.JavaCompile
plugins {
id 'java-library'
alias libs.plugins.lombok
alias libs.plugins.shadow
}
version = '3.0.0-26.2'
def apiVersion = '1.20'
def main = 'com.volmit.bile.BileTools'
def volmLibCoordinate = providers.gradleProperty("volmLibCoordinate").orElse("com.github.VolmitSoftware:VolmLib:master-SNAPSHOT").get()
// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
// ======================== WINDOWS =============================
// registerCustomOutputTask('Cyberpwn', 'C://Users/cyberpwn/Documents/development/server/plugins')
// ========================== UNIX ==============================
registerCustomOutputTaskUnix("PsychoLT", "/Users/brianfopiano/Developer/RemoteGit/[Minecraft Server]/consumers/plugin-consumers/dropins/plugins")
// ==============================================================
tasks.processResources {
inputs.properties(
'name': rootProject.name,
'version': version,
'main': main,
'apiVersion': apiVersion,
)
filesMatching('**/plugin.yml') {
expand(inputs.properties)
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
maven { url = 'https://jitpack.io' }
}
tasks.named('compileJava', JavaCompile) {
options.compilerArgs.add('-parameters')
options.encoding = 'UTF-8'
options.release.set(17)
}
tasks.named('compileTestJava', JavaCompile) {
options.compilerArgs.add('-parameters')
options.encoding = 'UTF-8'
options.release.set(17)
}
configurations {
spigotCompatibility
currentPaperCompatibility
currentSpigotCompatibility
}
dependencies {
compileOnly libs.paper
spigotCompatibility libs.spigot
currentPaperCompatibility libs.paperCurrent
currentSpigotCompatibility libs.spigotCurrent
implementation(volmLibCoordinate) {
changing = true
transitive = false
}
implementation libs.bstats
testImplementation libs.paper
testImplementation 'junit:junit:4.13.2'
}
configurations.configureEach {
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
resolutionStrategy.cacheDynamicVersionsFor(0, "seconds")
}
tasks.register('compileSpigotCompatibility', JavaCompile) {
source = sourceSets.main.java
classpath = files(sourceSets.main.compileClasspath.filter { File dependency ->
!dependency.name.startsWith('paper-api-')
}) + configurations.spigotCompatibility
destinationDirectory.set(layout.buildDirectory.dir('classes/java/spigotCompatibility'))
options.annotationProcessorPath = configurations.annotationProcessor
options.compilerArgs.add('-parameters')
options.encoding = 'UTF-8'
options.release.set(17)
}
tasks.register('compileCurrentPaperCompatibility', JavaCompile) {
source = sourceSets.main.java
classpath = files(sourceSets.main.compileClasspath.filter { File dependency ->
!dependency.name.startsWith('paper-api-')
}) + configurations.currentPaperCompatibility
destinationDirectory.set(layout.buildDirectory.dir('classes/java/currentPaperCompatibility'))
options.annotationProcessorPath = configurations.annotationProcessor
options.compilerArgs.add('-parameters')
options.encoding = 'UTF-8'
options.release.set(25)
}
tasks.register('compileCurrentSpigotCompatibility', JavaCompile) {
source = sourceSets.main.java
classpath = files(sourceSets.main.compileClasspath.filter { File dependency ->
!dependency.name.startsWith('paper-api-')
}) + configurations.currentSpigotCompatibility
destinationDirectory.set(layout.buildDirectory.dir('classes/java/currentSpigotCompatibility'))
options.annotationProcessorPath = configurations.annotationProcessor
options.compilerArgs.add('-parameters')
options.encoding = 'UTF-8'
options.release.set(25)
}
tasks.named('shadowJar') {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// bStats internals are reflection/callable driven, keep the minimizer off them.
minimize {
exclude(dependency('org.bstats:.*:.*'))
}
// bStats refuses to enable unless its package is relocated. VolmLib stays unrelocated on purpose.
relocate('org.bstats', 'com.volmit.bile.libs.bstats')
}
tasks.register('verifyCompatibilityArtifact') {
dependsOn tasks.named('shadowJar')
doLast {
File artifact = tasks.named('shadowJar').get().archiveFile.get().asFile
java.util.zip.ZipFile archive = new java.util.zip.ZipFile(artifact)
try {
java.util.Enumeration<? extends java.util.zip.ZipEntry> entries = archive.entries()
while (entries.hasMoreElements()) {
java.util.zip.ZipEntry entry = entries.nextElement()
if (!entry.name.endsWith('.class')) {
continue
}
java.io.DataInputStream input = new java.io.DataInputStream(archive.getInputStream(entry))
try {
long magic = Integer.toUnsignedLong(input.readInt())
if (magic != 0xCAFEBABEL) {
throw new GradleException("Invalid class file in ${artifact.name}: ${entry.name}")
}
input.readUnsignedShort()
int majorVersion = input.readUnsignedShort()
if (majorVersion > 61) {
throw new GradleException("${entry.name} requires class version ${majorVersion}; BileTools must remain Java 17 compatible")
}
} finally {
input.close()
}
}
java.util.zip.ZipEntry descriptor = archive.getEntry('plugin.yml')
if (descriptor == null) {
throw new GradleException("${artifact.name} does not contain plugin.yml")
}
String pluginYml = archive.getInputStream(descriptor).getText('UTF-8')
if (!pluginYml.readLines().contains('api-version: 1.20')) {
throw new GradleException("${artifact.name} does not declare api-version: 1.20")
}
} finally {
archive.close()
}
}
}
tasks.named('check') {
dependsOn tasks.named('compileSpigotCompatibility')
dependsOn tasks.named('compileCurrentPaperCompatibility')
dependsOn tasks.named('compileCurrentSpigotCompatibility')
dependsOn tasks.named('verifyCompatibilityArtifact')
}
tasks.named('build') {
dependsOn tasks.named('shadowJar')
dependsOn tasks.named('verifyCompatibilityArtifact')
}
tasks.register('biletools', Copy) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from tasks.named('shadowJar').flatMap { it.archiveFile }
into layout.buildDirectory.dir('out')
rename { "BileTools-${version}.jar" }
}
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_25)) {
System.err.println()
System.err.println('=========================================================================================================')
System.err.println("You must run gradle on Java 25 or newer. You are using ${JavaVersion.current()}")
System.err.println()
System.err.println('=== For IDEs ===')
System.err.println('1. Configure the project for Java 25')
System.err.println('2. Configure the bundled gradle to use Java 25 in settings')
System.err.println()
System.err.println('=== For Command Line (gradlew) ===')
System.err.println('1. Install JDK 25 from https://adoptium.net/temurin/releases/?version=25')
System.err.println('2. Set JAVA_HOME environment variable to the new jdk installation folder')
System.err.println('3. Open a new command prompt window to get the new environment variables if need be.')
System.err.println('=========================================================================================================')
System.err.println()
System.exit(69)
}
void registerCustomOutputTask(String name, String path) {
registerCustomOutputTask(name, path, true)
}
void registerCustomOutputTask(String name, String path, boolean doRename) {
if (!System.getProperty('os.name').toLowerCase().contains('windows')) {
return
}
createOutputTask(name, path, doRename)
}
void registerCustomOutputTaskUnix(String name, String path) {
registerCustomOutputTaskUnix(name, path, true)
}
void registerCustomOutputTaskUnix(String name, String path, boolean doRename) {
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
return
}
createOutputTask(name, path, doRename)
}
void createOutputTask(String name, String path, boolean doRename) {
tasks.register("build${name}", Copy) {
group = 'development'
outputs.upToDateWhen { false }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from tasks.named('shadowJar').flatMap { it.archiveFile }
into file(path)
if (doRename) rename { 'BileTools.jar' }
}
}