forked from SkriptLang/Skript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
446 lines (391 loc) · 15.4 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
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'
id 'java-library'
}
configurations {
testImplementation.extendsFrom testShadow
}
def project_version = "3.0-base"
def lib_version = "3.0-base"
allprojects {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
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/' }
maven { url 'https://raw.githubusercontent.com/Ultreon/corelibs/main/.mvnrepo/' }
}
}
configurations {
testImplementation.extendsFrom(implementation)
implementation {
canBeResolved = true
}
}
dependencies {
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.+'
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
implementation group: 'com.google.guava', name: 'guava', version: '32.1.3-jre'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
shadow implementation(group: 'commons-lang', name: 'commons-lang', version: '2.6')
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
implementation group: 'org.jetbrains', name: 'annotations', version: '23.0.0'
shadow implementation(group: "io.github.ultreon.corelibs", name: "events-v0", version: "0.2.0")
testImplementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.700'
testImplementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.+'
testImplementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
testImplementation group: 'com.google.guava', name: 'guava', version: '32.1.3-jre'
testImplementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
testImplementation group: 'org.jetbrains', name: 'annotations', version: '23.0.0'
implementation fileTree(dir: 'lib', include: '*.jar')
testShadow group: 'junit', name: 'junit', version: '4.13.2'
testShadow group: 'org.easymock', name: 'easymock', version: '5.0.1'
}
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
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
exclude "META-INF/*.SF"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
task build(overwrite: true, type: ShadowJar) {
archiveFileName = jarName ? 'Skript-' + project.version + '.jar' : jarName
from sourceSets.main.output
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
exclude "META-INF/*.SF"
}
// Excludes the tests for the build task. Should be using junit, junitJava17, junitJava8, 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 {
dependency('commons-lang:commons-lang:2.6')
}
relocate 'org.jetbrains', 'ch.njol.skript.shadow.org.jetbrains'
relocate 'org.intellij', 'ch.njol.skript.shadow.org.intellij'
relocate "org.apache.commons.lang.enums", "ch.njol.skript.shadow.org.apache.commons.lang.enums"
relocate "org.apache.commons.lang.enum", "ch.njol.skript.shadow.org.apache.commons.lang.enum1"
relocate "org.apache.commons.lang", "ch.njol.skript.shadow.org.apache.commons.lang"
manifest {
attributes(
'Name': 'ch/njol/skript',
'FMLModType': "GAMELIBRARY",
'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 {
mavenLocal()
maven {
url = 'https://maven.pkg.github.com/XyperCode/base-skript'
name = "BaseSkriptPackages"
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
task releaseJavadoc(type: Javadoc) {
title = project.name + ' ' + project.property('version')
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
options.encoding = 'UTF-8'
// currently our javadoc has a lot of errors, so we need to suppress the linter
options.addStringOption('Xdoclint:none', '-quiet')
}
// 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-github.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,
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 java8 = 8
def latestEnv = 'java21.json'
def latestJava = java21
def oldestJava = java8
def latestJUnitEnv = 'java17.json'
def latestJUnitJava = java17
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('skriptTestJava8', 'Runs tests on all Java 8 environments.', environments + 'java8', java8, 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 skriptTestJava8, skriptTestJava17, skriptTestJava21
}
createTestTask('JUnitQuick', 'Runs JUnit tests on one environment being the latest supported Java and Minecraft.', environments + latestJUnitEnv, latestJUnitJava, 0, Modifiers.JUNIT)
// Disabled as EasyMock 5.2.0 is required for Java 21 support
// However, we are currently using 5.0.1 (see https://github.com/SkriptLang/Skript/pull/6204#discussion_r1405302009)
//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('JUnitJava8', 'Runs JUnit tests on all Java 8 environments.', environments + 'java8', java8, 0, Modifiers.JUNIT)
tasks.register('JUnit') {
description = 'Runs JUnit tests on all environments.'
dependsOn JUnitJava8, JUnitJava17//, JUnitJava21
}
// Build flavor configurations
task githubResources(type: ProcessResources) {
from 'src/main/resources', {
include '**'
def channel = 'stable'
if (version.contains('pre'))
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : "$lib_version",
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-github', // SkriptLang build, distributed on Github
'release-channel' : channel, // Release channel, see above
'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',
'FMLModType': "GAMELIBRARY",
'Automatic-Module-Name': 'ch.njol.skript',
'Sealed': 'true'
)
}
}
task spigotResources(type: ProcessResources) {
from 'src/main/resources', {
include '**'
def channel = 'stable'
if (version.contains('pre'))
channel = 'prerelease'
filter ReplaceTokens, tokens: [
'version' : "$lib_version",
'today' : '' + LocalTime.now(),
'release-flavor' : 'skriptlang-spigot', // SkriptLang build, distributed on Spigot resources
'release-channel' : channel, // Release channel, see above
'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',
'FMLModType': "GAMELIBRARY",
'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()
project_version += '-nightly-' + hash
filter ReplaceTokens, tokens: [
'version' : "$lib_version-nightly-$hash",
'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 autoupdates 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',
'FMLModType': "GAMELIBRARY",
'Automatic-Module-Name': 'ch.njol.skript',
'Sealed': 'true'
)
}
}
javadoc {
dependsOn nightlyResources
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')
}