forked from TheComputerGeek2/MagicSpells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
603 lines (513 loc) · 19.3 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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
// Add -PDeploymentNaming to the build command to strip the jar filenames
// Of the version information (this is just for clean files on GitHub)
//
// Add -Prelease to the build command to version the jars with release versions
// (defaults to dev build labeling)
// possible concern: make sure that the timestamps for the jars are correct
// possible concern: make sure that the yml resources are always updated and correct timestamps
// TODO build the spigot server jars automatically as needed
// TODO create task to setup workspace
// TODO make sure the clean task cleans everything properly
// TODO make sure all builds can be cached where possible
// TODO clean up dependency management
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.3"
classpath 'de.undercouch:gradle-download-task:3.4.2'
classpath "com.sarhanm:gradle-versioner:2.4.0"
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'de.undercouch.download'
apply plugin: "com.sarhanm.versioner"
final String OPTION_DEPLOYMENT_NAMING = 'DeploymentNaming'
final String OPTION_RELEASE = 'release'
configurations {
spigot
mscore.extendsFrom(compile)
factions.extendsFrom(spigot)
teams.extendsFrom(spigot)
memory.extendsFrom(spigot)
towny.extendsFrom(spigot)
shop.extendsFrom(spigot)
}
ext {
magicspellsData = new MSConfig()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.0'
spigot magicspellsClasspathSpigot()
mscore magicspellsClasspathBase()
factions magicspellsClasspathFactions()
factions configurations.mscore.artifacts.getFiles()
teams configurations.mscore.artifacts.getFiles()
memory configurations.mscore.artifacts.getFiles()
towny configurations.mscore.artifacts.getFiles()
towny magicspellsClasspathTowny()
shop configurations.mscore.artifacts.getFiles()
shop magicspellsClasspathVault()
}
public class MSConfig {
String coreVersion = '3.6'
String coreSrcDir = 'src'
String coreBuildDir = 'bin'
String teamsVersion = '1.0'
String teamsSrcDir = 'src_teams'
String teamsBuildDir = 'bin_teams'
String memoryVersion = '1.2'
String memorySrcDir = 'src_memory'
String memoryBuildDir = 'bin_memory'
String shopVersion = '1.6'
String shopSrcDir = 'src_shop'
String shopBuildDir = 'bin_shop'
String townyVersion = '1.3'
String townySrcDir = 'src_towny'
String townyBuildDir = 'bin_towny'
String factionsVersion = '1.0'
String factionsSrcDir = 'src_factions'
String factionsBuildDir = 'bin_factions'
String distDir = 'dist'
String libDir = 'lib'
String docDir = 'doc'
// Java versions
def javaCoreVersion = '1.8'
def javaTeamsVersion = '1.8'
def javaMemoryVersion = '1.8'
def javaShopVersion = '1.8'
def javaTownyVersion = '1.8'
def javaFactionsVersion = '1.8'
//<tstamp><format property="datestamp" pattern="yyMMddHHmm"/></tstamp>
def datestampPattern = 'yyMMddHHmm'
def datestampString = "${-> new Date().format(datestampPattern)}"
// Resource retrieving
def resourceResidenceUrl = 'http://nexus.hc.to/content/repositories/pub_releases/com/bekvon/bukkit/residence/Residence/4.5.3.0/Residence-4.5.3.0.jar'
def resourceNcpUrl = 'https://ci.md-5.net/job/NoCheatPlus/lastSuccessfulBuild/artifact/target/NoCheatPlus.jar'
def resourcePlaceholderapiUrl = 'http://repo.extendedclip.com/content/repositories/placeholderapi/me/clip/placeholderapi/2.8.2/placeholderapi-2.8.2.jar'
def resourceGriefPreventionUrl = 'https://github.com/TechFortress/GriefPrevention/releases/download/16.8/GriefPrevention.jar'
def versionSuffix
String stringVersionCore
String stringVersionFactions
String stringVersionMemory
String stringVersionTeams
String stringVersionTowny
String stringVersionShop
}
MSConfig msconfig = ext.magicspellsData
def downloadFile(File file, URL url) {
if (!file.exists()) {
url.withInputStream{ i -> file.withOutputStream{ it << i }}
}
}
// FIXME this should be setup as a task instead of a method running on configuration time
// Ensures resource availability
def magicspellsGetResources() {
println 'Running the get resources phase'
File libFolder = project.file(project.ext.magicspellsData.libDir)
// Get Residence
downloadFile(new File(libFolder, 'Residence.jar'), new URL(project.ext.magicspellsData.resourceResidenceUrl))
// Get NoCheatPlus
downloadFile(new File(libFolder, 'NoCheatPlus.jar'), new URL(project.ext.magicspellsData.resourceNcpUrl))
// Get PlaceholderAPI
downloadFile(new File(libFolder, 'PlaceholderAPI.jar'), new URL(project.ext.magicspellsData.resourcePlaceholderapiUrl))
// Get GriefPrevention
downloadFile(new File(libFolder, 'GriefPrevention.jar'), new URL(project.ext.magicspellsData.resourceGriefPreventionUrl))
println 'Finished running the get resources phase'
}
task getResidence(type: Download) {
dest new File(project.file(project.ext.magicspellsData.libDir), 'Residence.jar')
src 'http://ltcraft.lt/Residence/download.php?file=Residence4.5.3.0.jar'
overwrite false
}
// FIXME this should not be run at configuration time
//magicspellsGetResources()
task downloadDependencies() {
group = 'Setup'
dependsOn = [
'getResidence'
]
doFirst {
magicspellsGetResources()
}
}
// FIXME fix up this task
task magicspellsBuildVersion() {
description = 'Assign version suffix in dev build format'
msconfig.versionSuffix = "dev-${-> msconfig.datestampString}"
}
// FIXME fix up this task
task magicspellsReleaseVersion() {
description = 'Assign version suffix in release format'
if (project.hasProperty("${OPTION_RELEASE}")) msconfig.versionSuffix = 'Release'
}
Spec<? super File> ymlFilter() {
return new Spec() {
boolean isSatisfiedBy(Object file) {
if (!(file instanceof File)) return false
return file.getName().endsWith("yml")
}
}
}
def magicspellsClean() {
// Delete old working directories
project.delete project.ext.magicspellsData.coreBuildDir, project.ext.magicspellsData.teamsBuildDir, project.ext.magicspellsData.memoryBuildDir, project.ext.magicspellsData.shopBuildDir, project.ext.magicspellsData.townyBuildDir, project.ext.magicspellsData.factionsBuildDir, project.ext.magicspellsData.docDir, project.ext.magicspellsData.distDir
project.file(project.ext.magicspellsData.distDir).mkdir()
}
project.tasks.getByPath("clean").doFirst({magicspellsClean()})
def cleanYmlFiles() {
def files = project.files(project.ext.magicspellsData.coreBuildDir)
.plus(project.files(project.ext.magicspellsData.teamsBuildDir))
.plus(project.files(project.ext.magicspellsData.memoryBuildDir))
.plus(project.files(project.ext.magicspellsData.shopBuildDir))
.plus(project.files(project.ext.magicspellsData.townyBuildDir))
.plus(project.files(project.ext.magicspellsData.factionsBuildDir))
.filter(project.ymlFilter())
project.delete files
}
def cleanDistFolder() {
project.delete project.ext.magicspellsData.distDir
project.file(project.ext.magicspellsData.distDir).mkdir()
}
// FIXME this should be setup as a task instead of a method running on configuration time
//magicspellsClean()
cleanDistFolder()
cleanYmlFiles()
def magicspellsClasspathBase() {
return magicspellsClasspathSpigot()
.plus(magicspellsClasspathEffectlib())
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}ProtocolLib.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}NoCheatPlus.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}WorldEdit.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}WorldGuard.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}LibsDisguises-9.0.9.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}Residence.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}PlaceholderAPI.jar"))
.plus(magicspellsClasspathVault())
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}GriefPrevention.jar"))
}
def magicspellsClasspathVault() {
return project.files("${-> project.ext.magicspellsData.libDir}${File.separator}Vault.jar")
}
def magicspellsClasspathEffectlib() {
return project.files("${-> project.ext.magicspellsData.libDir}${File.separator}EffectLib-4.0.jar")
}
def magicspellsClasspathSpigot() {
return project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.12.jar")
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.10.2.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.9.4.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.9.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.8.7.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.8-R0.1-SNAPSHOT.jar"))
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}spigot-1.11.2.jar"))
}
def magicspellsClasspathTowny() {
return project.files("${-> project.ext.magicspellsData.libDir}${File.separator}Towny.jar")
}
def magicspellsClasspathFactions() {
return project.files("${-> project.ext.magicspellsData.libDir}${File.separator}MassiveCore.jar")
.plus(project.files("${-> project.ext.magicspellsData.libDir}${File.separator}Factions.jar"))
}
// FIXME fix up this task
// FIXME do more of this at build time, not config time
task magicspellsCoreCompile(type: JavaCompile) {
description = 'Compile the main MagicSpells java files'
dependsOn = [
'downloadDependencies'
]
File buildDir = project.file(msconfig.coreBuildDir)
buildDir.mkdir()
destinationDir = buildDir
source(msconfig.coreSrcDir)
classpath = configurations.mscore
sourceCompatibility = msconfig.javaCoreVersion
msconfig.stringVersionCore = "${msconfig.coreVersion}-${msconfig.versionSuffix}"
}
FileCollection coreYml = null
task updateCoreYmlFiles() {
doFirst {
coreYml = project.files("${msconfig.coreBuildDir}").filter(ymlFilter())
}
}
task magicspellsCopyResourcesClean(type: Delete) {
dependsOn = [
"updateCoreYmlFiles"
]
doFirst {
setProperty("delete", coreYml)
}
}
// FIXME fix up this task
task magicspellsCoreCopyResources(type: Copy) {
description = 'Copy yml resources for MagicSpells'
from(msconfig.coreSrcDir) {
include "**${File.separator}*.yml"
}
expand(project.properties)
into "${msconfig.coreBuildDir}"
}
// FIXME do more of this at build time, not config time
task magicspellsCoreJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
description = 'Create the main MagicSpells jar'
dependsOn = [
'magicspellsCoreCompile',
'magicspellsCoreCopyResources'
]
archiveName = "MagicSpells-${msconfig.stringVersionCore}.jar"
if (project.hasProperty("${OPTION_DEPLOYMENT_NAMING}")) archiveName = 'MagicSpells.jar'
destinationDir = project.file(msconfig.distDir)
from("${msconfig.coreBuildDir}")
dependencies {
repositories {
mavenCentral()
}
dependency('org.apache.commons:commons-math3')
}
from (project.configurations.compile)
relocate 'org.apache.commons.math3', 'com.nisovin.magicspells.shaded.org.apache.commons'
magicspellsCoreJar.exclude "**${File.separator}*.xml", "**${File.separator}*pom.properties", "**${File.separator}**LocalizedFormats**"
println magicspellsCoreJar.excludes
}
// FIXME do more of this at build time, not config time
task magicspellsTeamsCompile(type: JavaCompile) {
description = 'Compile the teams addon'
dependsOn = [
'magicspellsCoreJar'
]
msconfig.stringVersionTeams = "${msconfig.teamsVersion}-${msconfig.versionSuffix}"
File buildDir = project.file(msconfig.teamsBuildDir)
buildDir.mkdir()
destinationDir = buildDir
source(msconfig.teamsSrcDir)
classpath = configurations.teams
sourceCompatibility = msconfig.javaTeamsVersion
}
// FIXME fix up this task
task magicspellsTeamsCopyResources(type: Copy) {
description = 'Copy yml resources for MagicSpellsTeams'
from(msconfig.teamsSrcDir) {
include "**${File.separator}*.yml"
}
expand(project.properties)
into "${msconfig.teamsBuildDir}"
}
// FIXME do more of this at build time, not config time
task magicspellsTeamsJar(type: Jar) {
description = 'Create the teams addon jar'
dependsOn = [
'magicspellsTeamsCompile',
'magicspellsTeamsCopyResources'
]
archiveName = "MagicSpellsTeams-${msconfig.teamsVersion}-${msconfig.versionSuffix}.jar"
if (project.hasProperty("${OPTION_DEPLOYMENT_NAMING}")) archiveName = 'MagicSpellsTeams.jar'
destinationDir = project.file(msconfig.distDir)
from("${msconfig.teamsBuildDir}")
}
// FIXME do more of this at build time, not config time
task magicspellsMemoryCompile(type: JavaCompile) {
description = 'Compile the memory addon'
dependsOn = [
'magicspellsCoreJar'
]
msconfig.stringVersionMemory = "${msconfig.memoryVersion}-${msconfig.versionSuffix}"
File buildDir = project.file(msconfig.memoryBuildDir)
buildDir.mkdir()
destinationDir = buildDir
source(msconfig.memorySrcDir)
classpath = configurations.memory
sourceCompatibility = msconfig.javaMemoryVersion
}
task magicspellsMemoryCopyResources(type: Copy) {
description = 'Copy yml resources for MagicSpellsMemory'
from(msconfig.memorySrcDir) {
include "**${File.separator}*.yml"
}
expand(project.properties)
into "${msconfig.memoryBuildDir}"
}
// FIXME do more of this at build time, not config time
// Create the memory jar file
task magicspellsMemoryJar(type: Jar) {
description = 'Create the memory addon jar'
dependsOn = [
'magicspellsMemoryCompile',
'magicspellsMemoryCopyResources'
]
archiveName = "MagicSpellsMemory-${msconfig.stringVersionMemory}.jar"
if (project.hasProperty("${OPTION_DEPLOYMENT_NAMING}")) archiveName = 'MagicSpellsMemory.jar'
destinationDir = project.file(msconfig.distDir)
from("${msconfig.memoryBuildDir}")
}
// FIXME do more of this at build time, not config time
// Compile shop addon
task magicspellsShopCompile(type: JavaCompile) {
description = 'Compile the shop addon'
dependsOn = [
'magicspellsCoreJar'
]
msconfig.stringVersionShop = "${msconfig.shopVersion}-${msconfig.versionSuffix}"
File buildDir = project.file(msconfig.shopBuildDir)
buildDir.mkdir()
destinationDir = buildDir
source(msconfig.shopSrcDir)
classpath = configurations.shop
sourceCompatibility = msconfig.javaShopVersion
}
task magicspellsShopCopyResources(type: Copy) {
description = 'Copy yml resources for MagicSpellsShop'
from(msconfig.shopSrcDir) {
include "**${File.separator}*.yml"
}
expand(project.properties)
into "${msconfig.shopBuildDir}"
}
// Create the shop jar file
task magicspellsShopJar(type: Jar) {
description = 'Create the shop addon jar'
dependsOn = [
'magicspellsShopCompile',
'magicspellsShopCopyResources'
]
archiveName = "MagicSpellsShop-${msconfig.shopVersion}-${msconfig.versionSuffix}.jar"
if (project.hasProperty("${OPTION_DEPLOYMENT_NAMING}")) archiveName = 'MagicSpellsShop.jar'
destinationDir = project.file(msconfig.distDir)
from("${msconfig.shopBuildDir}")
}
// FIXME do more of this at build time, not config time
// Compile towny addon
task magicspellsTownyCompile(type: JavaCompile) {
description = 'Compile the Towny addon'
dependsOn = [
'magicspellsCoreJar'
]
msconfig.stringVersionTowny = "${msconfig.townyVersion}-${msconfig.versionSuffix}"
File buildDir = project.file(msconfig.townyBuildDir)
buildDir.mkdir()
destinationDir = buildDir
source(msconfig.townySrcDir)
classpath = configurations.towny
sourceCompatibility = msconfig.javaTownyVersion
}
task magicspellsTownyCopyResources(type: Copy) {
description = 'Copy yml resources for MagicSpellsTowny'
from(msconfig.townySrcDir) {
include "**${File.separator}*.yml"
}
expand(project.properties)
into "${msconfig.townyBuildDir}"
}
// Create the towny jar file
task magicspellsTownyJar(type: Jar) {
description = 'Create the Towny addon jar'
dependsOn = [
'magicspellsTownyCompile',
'magicspellsTownyCopyResources'
]
archiveName = "MagicSpellsTowny-${msconfig.townyVersion}-${msconfig.versionSuffix}.jar"
if (project.hasProperty("${OPTION_DEPLOYMENT_NAMING}")) archiveName = 'MagicSpellsTowny.jar'
destinationDir = project.file(msconfig.distDir)
from("${msconfig.townyBuildDir}")
}
// Compile factions addon
task magicspellsFactionsCompile(type: JavaCompile) {
description = 'Compile the Factions addon'
dependsOn = [
'magicspellsCoreJar'
]
msconfig.stringVersionFactions = "${msconfig.factionsVersion}-${msconfig.versionSuffix}"
File buildDir = project.file(msconfig.factionsBuildDir)
buildDir.mkdir()
destinationDir = buildDir
source(msconfig.factionsSrcDir)
classpath = configurations.factions
sourceCompatibility = msconfig.javaFactionsVersion
}
task magicspellsFactionsCopyResources(type: Copy) {
description = 'Copy yml resources for MagicSpellsFactions'
from(msconfig.factionsSrcDir) {
include "**${File.separator}*.yml"
}
expand(project.properties)
into "${msconfig.factionsBuildDir}"
}
// Create the factions jar file
task magicspellsFactionsJar(type: Jar) {
description = 'Create the Factions addon jar'
dependsOn = [
'magicspellsFactionsCompile',
'magicspellsFactionsCopyResources'
]
archiveName = "MagicSpellsFactions-${msconfig.factionsVersion}-${msconfig.versionSuffix}.jar"
if (project.hasProperty("${OPTION_DEPLOYMENT_NAMING}")) archiveName = 'MagicSpellsFactions.jar'
destinationDir = project.file(msconfig.distDir)
from("${msconfig.factionsBuildDir}")
}
// Zip everything
task magicspellsZip(type: Zip) {
description = 'Zip up the MagicSpells jars'
dependsOn = [
'magicspellsCoreJar',
'magicspellsMemoryJar',
'magicspellsShopJar',
'magicspellsTeamsJar',
'magicspellsTownyJar',
'magicspellsFactionsJar'
]
File distDir = project.file(msconfig.distDir)
from magicspellsCoreJar, magicspellsMemoryJar, magicspellsShopJar, magicspellsTeamsJar, magicspellsTownyJar, magicspellsFactionsJar
eachFile({
fcd -> println(fcd.getName())
})
archiveName 'MagicSpells.zip'
destinationDir(distDir)
}
task magicspellsJarAll() {
description = 'Make all the jars and zip them'
dependsOn = [
'magicspellsCoreJar',
'magicspellsTeamsJar',
'magicspellsMemoryJar',
'magicspellsShopJar',
'magicspellsTownyJar',
'magicspellsFactionsJar',
'magicspellsZip'
]
}
task magicspellsBuild() {
dependsOn = [
'magicspellsBuildVersion',
'magicspellsJarAll'
]
}
task magicspellsRelease() {
dependsOn = [
'magicspellsReleaseVersion',
'magicspellsJarAll'
]
}
apply plugin: 'maven-publish'
group = 'com.github.TheComputerGeek2'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'com.github.TheComputerGeek2'
version = "MagicSpells-${msconfig.coreVersion}-${gitdata.getCommit()}"
artifact magicspellsCoreJar
}
}
}
artifacts {
mscore magicspellsCoreJar
teams magicspellsTeamsJar
memory magicspellsMemoryJar
shop magicspellsShopJar
towny magicspellsTownyJar
factions magicspellsFactionsJar
archives magicspellsZip
}