-
-
Notifications
You must be signed in to change notification settings - Fork 365
/
build.gradle
400 lines (359 loc) · 13.9 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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.apache.tools.ant.filters.ReplaceTokens
import java.time.LocalTime
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'maven-publish'
id 'java'
}
configurations {
testImplementation.extendsFrom testShadow
}
allprojects {
repositories {
mavenCentral()
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.papermc.io/repository/maven-public/' }
maven { url = 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } // needed for paper adventure snapshot
maven { url 'https://ci.emc.gs/nexus/content/groups/aikar/' }
}
}
dependencies {
shadow group: 'io.papermc', name: 'paperlib', version: '1.0.8'
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2'
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.2'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21-R0.1-SNAPSHOT'
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'
implementation group: 'com.sk89q.worldguard', name: 'worldguard-legacy', version: '7.0.0-SNAPSHOT'
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.3', {
exclude group: 'org.bstats', module: 'bstats-bukkit'
}
implementation fileTree(dir: 'lib', include: '*.jar')
testShadow group: 'junit', name: 'junit', version: '4.13.2'
testShadow group: 'org.easymock', name: 'easymock', version: '5.4.0'
}
task checkAliases {
description 'Checks for the existence of the aliases.'
doLast {
def aliasFolder = project.file('skript-aliases')
if (!aliasFolder.exists() || aliasFolder.listFiles().length == 0) {
throw new InvalidUserDataException('Aliases are missing from \'skript-aliases\' folder. Consider fetching submodules with \'git submodule update --init\'.')
}
}
}
task testJar(type: ShadowJar) {
dependsOn(compileTestJava)
archiveFileName = 'Skript-JUnit.jar'
from sourceSets.test.output, sourceSets.main.output, project.configurations.testShadow
}
task jar(overwrite: true, type: ShadowJar) {
dependsOn checkAliases
archiveFileName = jarName ? 'Skript-' + project.version + '.jar' : jarName
from sourceSets.main.output
}
task build(overwrite: true, type: ShadowJar) {
archiveFileName = jarName ? 'Skript-' + project.version + '.jar' : jarName
from sourceSets.main.output
}
// Excludes the tests for the build task. Should be using JUnitQuick, JUnitJava21, JUnitJava17, JUnitJava11, skriptTest, quickTest.
// We do not want tests to run for building. That's time consuming and annoying. Especially in development.
test {
exclude '**/*'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = 'sources'
}
tasks.withType(ShadowJar) {
configurations = [
project.configurations.shadow
]
dependencies {
include(dependency('io.papermc:paperlib'))
include(dependency('org.bstats:bstats-bukkit'))
include(dependency('org.bstats:bstats-base'))
include(dependency('net.kyori:adventure-text-serializer-bungeecord'))
}
relocate 'io.papermc.lib', 'ch.njol.skript.paperlib'
relocate 'org.bstats', 'ch.njol.skript.bstats'
manifest {
attributes(
'Name': 'ch/njol/skript',
'Automatic-Module-Name': 'ch.njol.skript',
'Sealed': 'true'
)
}
from 'skript-aliases', {
into 'aliases-english' // Change this if we get aliases in other languages
}
}
processResources {
filter ReplaceTokens, tokens: [
'version' : project.property('version'),
'today' : 'unknown', // Don't leak information about system this was built on
'release-flavor' : 'selfbuilt-unknown', // Note: 'selfbuilt' prefix makes updater report a custom build
'release-channel' : 'none', // No updates, so anything else wouldn't make sense
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // Disable update checking
'release-source' : '',
'release-download': 'null'
]
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.github.SkriptLang'
artifactId 'Skript'
version project.version
artifact sourceJar
artifact tasks.jar
}
}
repositories {
maven {
name = 'repo'
url = 'https://repo.skriptlang.org/releases'
credentials {
username = System.getenv('MAVEN_USERNAME')
password = System.getenv('MAVEN_PASSWORD')
}
}
}
}
// Task to check that test scripts are named correctly
tasks.register('testNaming') {
doLast {
// Regression tests
for (def file : project.file('src/test/skript/tests/regressions').listFiles()) {
def name = file.getName()
if (name.toLowerCase(Locale.ENGLISH) != name) {
throw new InvalidUserDataException('invalid test name: ' + name)
}
}
// Syntax tests
for (def dir : project.file('src/test/skript/tests/syntaxes').listFiles()) {
for (def file : dir.listFiles()) {
def name = file.getName()
if (!name.startsWith('.') && !Character.isJavaIdentifierStart(name.codePointAt(0))) {
throw new InvalidUserDataException('invalid test name: ' + name)
}
}
}
}
}
enum Modifiers {
DEV_MODE, GEN_NIGHTLY_DOCS, GEN_RELEASE_DOCS, DEBUG, PROFILE, JUNIT
}
// Create a test task with given name, environments dir/file, dev mode and java version.
// -1 on the timeout means it'll be disabled.
void createTestTask(String name, String desc, String environments, int javaVersion, long timeout, Modifiers... modifiers) {
if (timeout == 0)
timeout = 300000 // 5 minutes
boolean junit = modifiers.contains(Modifiers.JUNIT)
boolean releaseDocs = modifiers.contains(Modifiers.GEN_RELEASE_DOCS)
boolean docs = modifiers.contains(Modifiers.GEN_NIGHTLY_DOCS) || releaseDocs
def artifact = 'build' + File.separator + 'libs' + File.separator
if (junit) {
artifact += 'Skript-JUnit.jar'
} else if (releaseDocs) {
artifact += 'Skript-' + version + '.jar'
} else {
artifact += 'Skript-nightly.jar'
}
tasks.register(name, JavaExec) {
description = desc
if (junit) {
dependsOn testJar
} else if (releaseDocs) {
dependsOn githubRelease, testNaming
} else {
dependsOn nightlyRelease, testNaming
}
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
if (modifiers.contains(Modifiers.DEV_MODE)) {
standardInput = System.in
}
group = 'execution'
classpath = files([
artifact,
project.configurations.runtimeClasspath.find { it.name.startsWith('gson') },
sourceSets.main.runtimeClasspath
])
main = 'ch.njol.skript.test.platform.PlatformMain'
args = [
'build/test_runners',
junit ? 'src/test/skript/junit' : 'src/test/skript/tests',
'src/test/resources/runner_data',
environments,
modifiers.contains(Modifiers.DEV_MODE),
docs,
junit,
modifiers.contains(Modifiers.DEBUG),
project.findProperty('verbosity') ?: "null",
timeout
]
// Do first is used when throwing exceptions.
// This way it's not called when defining the task.
doFirst {
if (!gradle.taskGraph.hasTask(":tasks") && !gradle.startParameter.dryRun && modifiers.contains(Modifiers.PROFILE)) {
if (!project.hasProperty('profiler'))
throw new MissingPropertyException('Add parameter -Pprofiler=<path to profiler>', 'profiler', String.class)
args += '-agentpath:' + project.property('profiler') + '=port=8849,nowait'
}
}
}
}
def java21 = 21
def java17 = 17
def java11 = 11
def latestEnv = 'java21/paper-1.21.0.json'
def latestJava = java21
def oldestJava = java11
def latestJUnitEnv = latestEnv
def latestJUnitJava = latestJava
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(latestJava))
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['-source', '' + oldestJava, '-target', '' + oldestJava]
}
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
// Register different Skript testing tasks
String environments = 'src/test/skript/environments/';
String env = project.property('testEnv') == null ? latestEnv : project.property('testEnv') + '.json'
int envJava = project.property('testEnvJavaVersion') == null ? latestJava : Integer.parseInt(project.property('testEnvJavaVersion') as String)
createTestTask('quickTest', 'Runs tests on one environment being the latest supported Java and Minecraft.', environments + latestEnv, latestJava, 0)
createTestTask('skriptTestJava21', 'Runs tests on all Java 21 environments.', environments + 'java21', java21, 0)
createTestTask('skriptTestJava17', 'Runs tests on all Java 17 environments.', environments + 'java17', java17, 0)
createTestTask('skriptTestJava11', 'Runs tests on all Java 11 environments.', environments + 'java11', java11, 0)
createTestTask('skriptTestDev', 'Runs testing server and uses \'system.in\' for command input, stop server to finish.', environments + env, envJava, 0, Modifiers.DEV_MODE, Modifiers.DEBUG)
createTestTask('skriptProfile', 'Starts the testing server with JProfiler support.', environments + latestEnv, latestJava, -1, Modifiers.PROFILE)
createTestTask('genNightlyDocs', 'Generates the Skript documentation website html files.', environments + env, envJava, 0, Modifiers.GEN_NIGHTLY_DOCS)
createTestTask('genReleaseDocs', 'Generates the Skript documentation website html files for a release.', environments + env, envJava, 0, Modifiers.GEN_RELEASE_DOCS)
tasks.register('skriptTest') {
description = 'Runs tests on all environments.'
dependsOn skriptTestJava11, skriptTestJava17, skriptTestJava21
}
createTestTask('JUnitQuick', 'Runs JUnit tests on one environment being the latest supported Java and Minecraft.', environments + latestJUnitEnv, latestJUnitJava, 0, Modifiers.JUNIT)
createTestTask('JUnitJava21', 'Runs JUnit tests on all Java 21 environments.', environments + 'java21', java21, 0, Modifiers.JUNIT)
createTestTask('JUnitJava17', 'Runs JUnit tests on all Java 17 environments.', environments + 'java17', java17, 0, Modifiers.JUNIT)
createTestTask('JUnitJava11', 'Runs JUnit tests on all Java 11 environments.', environments + 'java11', java11, 0, Modifiers.JUNIT)
tasks.register('JUnit') {
description = 'Runs JUnit tests on all environments.'
dependsOn JUnitJava11, JUnitJava17, JUnitJava21
}
// Build flavor configurations
task githubResources(type: ProcessResources) {
from 'src/main/resources', {
include '**'
version = project.property('version')
def channel = 'stable'
if (version.contains('-'))
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-github', // SkriptLang build, distributed on Github
'release-channel' : channel, // Release channel, see above
'release-updater' : 'ch.njol.skript.update.GithubChecker', // Github API client
'release-source' : 'https://api.github.com/repos/SkriptLang/Skript/releases', // Github API URL
'release-download': 'null' // Update checker will figure it out
]
}
into 'build/resources/main'
}
task githubRelease(type: ShadowJar) {
from sourceSets.main.output
dependsOn githubResources
archiveFileName = 'Skript-' + version +'.jar'
manifest {
attributes(
'Name': 'ch/njol/skript',
'Automatic-Module-Name': 'ch.njol.skript',
'Sealed': 'true'
)
}
}
task spigotResources(type: ProcessResources) {
from 'src/main/resources', {
include '**'
version = project.property('version')
def channel = 'stable'
if (version.contains('-'))
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-spigot', // SkriptLang build, distributed on Spigot resources
'release-channel' : channel, // Release channel, see above
'release-updater' : 'ch.njol.skript.update.GithubChecker', // Github API client
'release-source' : 'https://api.github.com/repos/SkriptLang/Skript/releases', // Github API URL
'release-download': '\'http://example.com\'' // TODO insert Spigot URL
]
}
into 'build/resources/main'
}
task spigotRelease(type: ShadowJar) {
from sourceSets.main.output
dependsOn spigotResources
archiveFileName = 'Skript-spigot.jar'
manifest {
attributes(
'Name': 'ch/njol/skript',
'Automatic-Module-Name': 'ch.njol.skript',
'Sealed': 'true'
)
}
}
task nightlyResources(type: ProcessResources) {
from 'src/main/resources', {
include '**'
def hash = 'git rev-parse --short HEAD'.execute().text.trim()
version = project.property('version') + '-nightly-' + hash
filter ReplaceTokens, tokens: [
'version' : version,
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-nightly', // SkriptLang build, automatically done by CI
'release-channel' : 'prerelease', // No update checking, but these are VERY unstable
'release-updater' : 'ch.njol.skript.update.NoUpdateChecker', // No auto updates for now
'release-source' : '',
'release-download': 'null'
]
}
into 'build/resources/main'
}
task nightlyRelease(type: ShadowJar) {
from sourceSets.main.output
dependsOn nightlyResources
archiveFileName = 'Skript-nightly.jar'
manifest {
attributes(
'Name': 'ch/njol/skript',
'Automatic-Module-Name': 'ch.njol.skript',
'Sealed': 'true'
)
}
}
javadoc {
mustRunAfter(tasks.withType(ProcessResources))
title = 'Skript ' + project.property('version')
source = sourceSets.main.allJava
exclude("ch/njol/skript/conditions/**")
exclude("ch/njol/skript/expressions/**")
exclude("ch/njol/skript/effects/**")
exclude("ch/njol/skript/events/**")
exclude("ch/njol/skript/sections/**")
exclude("ch/njol/skript/structures/**")
exclude("ch/njol/skript/lang/function/EffFunctionCall.java")
exclude("ch/njol/skript/lang/function/ExprFunctionCall.java")
exclude("ch/njol/skript/hooks/**")
exclude("ch/njol/skript/test/**")
classpath = configurations.compileClasspath + sourceSets.main.output
options.encoding = 'UTF-8'
// currently our javadoc has a lot of errors, so we need to suppress the linter
options.addStringOption('Xdoclint:none', '-quiet')
}