-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.gradle
1785 lines (1492 loc) · 59.4 KB
/
common.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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// =================================================
// ____ __
// / _/____ ___ ____ ____ _____ / /_ _____
// / / / __ `__ \ / __ \ / __ \ / ___// __// ___/
// _/ / / / / / / // /_/ // /_/ // / / /_ (__ )
// /___//_/ /_/ /_// .___/ \____//_/ \__//____/
// /_/
//
// =================================================
import com.github.spotbugs.snom.SpotBugsTask
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.json.StringEscapeUtils
import io.franzbecker.gradle.lombok.task.DelombokTask
import org.apache.tools.ant.filters.ReplaceTokens
import org.myire.munge.TransformTask
import java.util.stream.Collectors
import static com.xlson.groovycsv.CsvParser.parseCsv
// =============================================================
// ____ ____ _ _ __ _
// / __ \ ___ / __/(_)____ (_)/ /_ (_)____ ____ _____
// / / / // _ \ / /_ / // __ \ / // __// // __ \ / __ \ / ___/
// / /_/ // __// __// // / / // // /_ / // /_/ // / / /(__ )
// /_____/ \___//_/ /_//_/ /_//_/ \__//_/ \____//_/ /_//____/
//
// =============================================================
final String NONE = "none"
final String BUNGEECORD = "bungeecord"
final String VELOCITY = "velocity"
final String SPIGOT = "spigot"
final String SPONGE = "sponge"
final String FORGE = "forge"
final String SPONGEFORGE = "spongeforge"
final String NUKKIT = "nukkit"
ext {
if (project.hasProperty("buildOffset")) {
if (buildOffset instanceof String)
buildOffset = Integer.parseInt(buildOffset)
} else
buildOffset = 0
gitDescription = "git describe --tags --dirty".execute(null, projectDir).text.trim()
isSnapshot = getBuildType() == "SNAPSHOT"
isDev = isSnapshot || getBuildType() == "DEV"
}
def getBuild() {
def commits = "git rev-list --count HEAD".execute(null, projectDir).text.trim()
return (project.buildOffset + commits.toInteger() + (isSnapshot? 1 : 0)).toString()
}
def getBuildType() {
if (project.gitDescription.endsWith("dirty"))
return "SNAPSHOT"
else if(project.gitDescription.contains("-"))
return "DEV"
else
return "RELEASE"
}
def getVersion() {
def branch = (project.hasProperty("branchName") ?
branchName.replaceFirst("^refs/(?:heads|tags|pull)/", "") :
("git describe --all".execute().text.trim().replaceFirst(".*?/", ""))).replaceAll("/|\\\\", "_")
def tempVersion = Arrays.stream(gitDescription.replaceAll("^v|-.*", "").split("\\."), 0, 3).map{num -> Integer.parseInt(num)}.toArray()
if (isDev) {
if (project.hasProperty("major")) {
tempVersion[0]++;
tempVersion[1] = 0;
tempVersion[2] = 0;
} else if (project.hasProperty("minor")) {
tempVersion[1]++;
tempVersion[2] = 0;
} else {
tempVersion[2]++;
}
}
def baseVersion = Arrays.stream(tempVersion).map{num -> Integer.toString(num)}.collect(Collectors.joining(".")) + ".${project.buildNum}"
if ((branch != "master") && !branch.matches("^v\\d+\\.\\d+.\\d+\$"))
baseVersion += "-${branch}"
if (buildType != "RELEASE")
baseVersion += "-${buildType}"
return baseVersion
}
def getChangelog() {
final String noChangelog = "*No Changelog*"
try {
File changelogFile = file("CHANGELOG.md")
if (!changelogFile.exists()) {
changelogFile = file("CHANGELOG.txt")
if (!changelogFile.exists())
return noChangelog
}
def text = changelogFile.text
def changelogPieces = text.split("(?m)^(?:Version )?\\d+\\.\\d+\\.\\d+\\S*\\R[-=]+\$", 3);
return (changelogPieces.length >= 2)? changelogPieces[1].trim() : text
} catch(IOException e) {
println e
}
return noChangelog
}
def printCoverageText(projectName, coverageInstructions, coverageBranches, coverageLines, coverageComplexity, coverageMethods) {
println String.format("Covered %.2f%% of instructions for ${projectName}.", ((double)coverageInstructions[1] / (double)coverageInstructions[0]) * 100.0)
println String.format("Covered %.2f%% of branches for ${projectName}.", ((double)coverageBranches[1] / (double)coverageBranches[0]) * 100.0)
println String.format("Covered %.2f%% of lines for ${projectName}.", ((double)coverageLines[1] / (double)coverageLines[0]) * 100.0)
println String.format("Covered %.2f%% of complexity for ${projectName}.", ((double)coverageComplexity[1] / (double)coverageComplexity[0]) * 100.0)
println String.format("Covered %.2f%% of methods for ${projectName}.", ((double)coverageMethods[1] / (double)coverageMethods[0]) * 100.0)
}
def signJar(archivePath) {
if (project.hasProperty("keyStoreAlias") && project.hasProperty("keyStore") && project.hasProperty("keyStorePass")) {
ant.signjar(
jar: archivePath,
alias: project.keyStoreAlias,
keystore: project.keyStore,
storepass: project.keyStorePass,
preservelastmodified: true
)
} else {
println "WARNING!!!\tCannot sign jar!"
}
}
def getDiscordGroupPing(groupName) {
return (discordGroupIdMapping.containsKey(groupName))? "<@&${discordGroupIdMapping.getProperty(groupName)}>" : "@$groupName"
}
def getMavenUrl() {
return "${-> project.tasks.uploadArchives.repositories.mavenDeployer.repository.url}" +
"${project.group.replace('.', '/')}/${project.archivesBaseName}/${project.version}/${project.archivesBaseName}-${project.version}.jar"
}
def isLocalMaven() {
return project.tasks.uploadArchives.repositories.mavenDeployer.repository.url.startsWith("file://")
}
// Print JVM version etc
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
// ==========================================
//
// ____ __ _
// / __ \ / /__ __ ____ _ (_)____ _____
// / /_/ // // / / // __ `// // __ \ / ___/
// / ____// // /_/ // /_/ // // / / /(__ )
// /_/ /_/ \__,_/ \__, //_//_/ /_//____/
// /____/
//
// ==========================================
apply plugin: "java-library"
apply plugin: "jacoco"
apply plugin: "maven"
apply plugin: "maven-publish"
apply plugin: "signing"
apply plugin: "eclipse"
apply plugin: "idea"
// ===============================================
//
// _____ __ __ _
// / ___/ ___ / /_ / /_ (_)____ ____ _ _____
// \__ \ / _ \ / __// __// // __ \ / __ `// ___/
// ___/ // __// /_ / /_ / // / / // /_/ /(__ )
// /____/ \___/ \__/ \__//_//_/ /_/ \__, //____/
// /____/
//
// ===============================================
if (!project.hasProperty("type")) {
throw new NoSuchElementException("No type is specified!")
} else if ((type != NONE) && (type != BUNGEECORD) && (type != VELOCITY) && (type != SPIGOT) && (type != SPONGE) && (type != FORGE) && (type != SPONGEFORGE) && (type != NUKKIT)) {
throw new IllegalArgumentException("The type \"${type}\" is unknown.\nUse either \"${NONE}\", \"${BUNGEECORD}\", \"${VELOCITY}\", \"${SPIGOT}\", \"${SPONGE}\", \"${FORGE}\", \"${SPONGEFORGE}\" or \"${NUKKIT}\"")
} else if (!project.hasProperty("pluginId")) {
throw new NoSuchElementException("No pluginId is specified!")
}
ext {
// Environment Variables
if (System.env.keyStoreAlias != null) keyStoreAlias = System.env.keyStoreAlias
if (System.env.keyStore != null) keyStore = System.env.keyStore
if (System.env.keyStorePass != null) keyStorePass = System.env.keyStorePass
if (System.env.keyId != null) ext."signing.keyId" = System.env.keyId
if (System.env.password != null) ext."signing.password" = System.env.password
if (System.env.secretKeyRingFile != null) ext."signing.secretKeyRingFile" = System.env.secretKeyRingFile
if (System.env.codacyApiToken != null) codacyApiToken = System.env.codacyApiToken
if (System.env.oreDeployApiKey != null) ext.oreDeployApiKey = System.env.oreDeployApiKey
if (System.env.curseForgeApiKey != null) curseForgeApiKey = System.env.curseForgeApiKey
if (System.env.devUpdateWebHook != null) devUpdateWebHook = System.env.devUpdateWebHook
if (System.env.releaseWebHook != null) releaseWebHook = System.env.releaseWebHook
if (System.env.releaseWebHook != null) discordGroupIdMapping = System.env.discordGroupIdMapping
if (System.env.testSecrets != null)
testSecrets = System.env.testSecrets
else
testSecrets = "{}"
if (!project.hasProperty("pluginName")) pluginName = name
if (!project.hasProperty("baseGroup")) baseGroup = "team.aura_dev"
buildNum = getBuild()
buildType = getBuildType()
if (project.hasProperty("signJar")) {
if (signJar instanceof String)
signJar = Boolean.parseBoolean(signJar)
} else
signJar = false
if (project.hasProperty("useStats")) {
if (useStats instanceof String)
useStats = Boolean.parseBoolean(useStats)
} else
useStats = (type != NONE) && (type != FORGE) && (type != NUKKIT)
if (project.hasProperty("customCharts")) {
if (customCharts instanceof String)
customCharts = Boolean.parseBoolean(customCharts)
} else
customCharts = false
if (project.hasProperty("useRootValues")) {
if (useRootValues instanceof String)
useRootValues = Boolean.parseBoolean(useRootValues)
} else
useRootValues = false
if (project.hasProperty("hasApi")) {
if (hasApi instanceof String)
hasApi = Boolean.parseBoolean(hasApi)
} else
hasApi = false
if (project.hasProperty("showMinecraftVersion")) {
if (showMinecraftVersion instanceof String)
showMinecraftVersion = Boolean.parseBoolean(showMinecraftVersion)
} else
showMinecraftVersion = (type == FORGE)
if (project.hasProperty("apiDependsOnPlatform")) {
if (apiDependsOnPlatform instanceof String)
apiDependsOnPlatform = Boolean.parseBoolean(apiDependsOnPlatform)
} else
apiDependsOnPlatform = true
if (project.hasProperty("enableShadow")) {
if (enableShadow instanceof String)
enableShadow = Boolean.parseBoolean(enableShadow)
} else
enableShadow = useStats
if (project.hasProperty("useMixins")) {
if (useMixins instanceof String)
useMixins = Boolean.parseBoolean(useMixins)
useMixins = useMixins && (type == SPONGEFORGE)
} else
useMixins = false
if (project.hasProperty("isOnOre")) {
if ((isOnOre instanceof String) && (isOnOre != "auto"))
isOnOre = Boolean.parseBoolean(isOnOre)
} else
isOnOre = "auto"
isOnOre = ((type == SPONGE) || (type == FORGE) || (type == SPONGEFORGE)) ? isOnOre : false
if (project.hasProperty("enableMockTesting")) {
if (enableMockTesting instanceof String)
enableMockTesting = Boolean.parseBoolean(enableMockTesting)
} else
enableMockTesting = false
shouldSign = project.hasProperty("signing.keyId") && project.hasProperty("signing.password") && project.hasProperty("signing.secretKeyRingFile")
baseMainDirResources = ["CHANGELOG", "CHANGELOG.md", "CHANGELOG.txt", "LICENSE", "LICENSE.md", "LICENSE.txt", "README", "README.md", "README.txt"]
mainDirResources =
fileTree(dir: file(projectDir), includes: baseMainDirResources) +
fileTree(dir: file(rootProject.projectDir), includes: baseMainDirResources)
// default versions
if (!project.hasProperty("java_version")) java_version = "17"
if (!project.hasProperty("lombok_version")) lombok_version = "1.18.32"
if (!project.hasProperty("lombok_hash")) lombok_hash = "97574674e2a25f567a313736ace00df8787d443de316407d57fc877d9f19a65d"
if (!project.hasProperty("spotBugs_version")) spotBugs_version = "4.8.4"
if (!project.hasProperty("mockito_version")) mockito_version = "3.12.4"
if (!project.hasProperty("powerMock_version")) powerMock_version = "2.0.9"
if (!project.hasProperty("bungeecoord_version")) bungeecoord_version = "1.20-R0.3-SNAPSHOT"
if (!project.hasProperty("velocity_version")) velocity_version = "3.1.1"
if (!project.hasProperty("spigot_version")) spigot_version = "1.20.6-R0.1-SNAPSHOT"
if (!project.hasProperty("sponge_version")) sponge_version = "10.0.0"
if (!project.hasProperty("nukkit_version")) nukkit_version = "2.0.0-SNAPSHOT"
if (!project.hasProperty("minecraft_version")) minecraft_version = "1.12.2"
if (!project.hasProperty("forge_version")) forge_version = "14.23.5.2854"
if (!project.hasProperty("mapping_version")) mapping_version = "stable_39-1.12"
if (!project.hasProperty("mixin_version")) mixin_version = "0.8.2"
if (!project.hasProperty("bStats_version")) bStats_version = "3.0.2"
// Processing variables
if (project.hasProperty("discordGroupIdMapping")) {
String textMapping = discordGroupIdMapping
discordGroupIdMapping = new Properties()
discordGroupIdMapping.load(new StringReader(textMapping))
} else
discordGroupIdMapping = new Properties()
if ((isOnOre == "auto") || ((isOnOre instanceof Boolean) && isOnOre)) {
File cacheFile = new File(project.buildDir, "oreProjectData.json")
cacheFile.parentFile.mkdirs()
try {
def oreProjectData = null
if (cacheFile.exists() &&
(groovy.time.TimeCategory.minus(new Date(), new Date(cacheFile.lastModified())).days < 7)) {
try {
oreProjectData = new JsonSlurper().parse(cacheFile);
} catch (IOException e) {
// Ignore
}
}
if (oreProjectData == null) {
oreProjectData = de.dosmike.sponge.pluginpublisher.tasks.TaskFunctors.runOreProjectLookup(null, pluginId)
cacheFile.text = oreProjectData
// Converting into a Groovy JSON object
oreProjectData = new JsonSlurper().parseText(oreProjectData.toString())
}
oreNamespace = oreProjectData.namespace.owner
oreSlug = oreProjectData.namespace.slug
isOnOre = true
} catch (Exception e) {
if ((isOnOre instanceof Boolean) && isOnOre)
println "WARNING: isOnOre was set to true, but the project couldn't be found on Ore, or your API key is missing the \"view_public_info\" permission!"
cacheFile.text = "{\"error\":\"${StringEscapeUtils.escapeJava(e.getMessage())}\"}"
isOnOre = false
}
}
}
version = getVersion()
if (description == null) description = "Empty description"
if (project != rootProject) ext.baseGroup = project.parent.group
group = "${baseGroup}.${pluginId}".toString()
if (showMinecraftVersion)
archivesBaseName += "-${minecraft_version}"
ext {
// bStats
if (useStats) bStatsName = "bstats-" + ((type == SPIGOT)? "bukkit" : ((type == SPONGEFORGE)? "sponge" : type)) + (customCharts? "" : "-lite")
// Common Manifest
commonManifest = {
attributes(
"Specification-Title": pluginId,
"Specification-Version": "1",
"Specification-Vendor": "Aura Development Team",
"Implementation-Title": pluginName,
"Implementation-Version": version,
"Implementation-Vendor": "Aura Development Team",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
)
}
// JSON patterns
jsonPatterns = ["mcmod.info", "**/*.json", "**/*.mcmeta"]
// PNG patterns
pngPatterns = ["**/*.png"]
// Common POM
commonPom = project.pom {
def baseProject = useRootValues? rootProject : project
groupId = group
version = version
artifactId = archivesBaseName
project {
name baseProject.archivesBaseName
packaging "jar"
description baseProject.description
url "https://gitlab.aura-dev.team/AuraDev/${rootProject.archivesBaseName}"
scm {
url "https://gitlab.aura-dev.team/AuraDev/${rootProject.archivesBaseName}"
connection "scm:git:git@gitlab.aura-dev.team:AuraDev/${rootProject.archivesBaseName}.git"
developerConnection "scm:git:gitlab.aura-dev.team:AuraDev/${rootProject.archivesBaseName}.git"
}
issueManagement {
system "github"
url "https://github.com/AuraDevelopmentTeam/${rootProject.archivesBaseName}/issues"
}
licenses {
license {
name "License"
url "https://github.com/AuraDevelopmentTeam/${rootProject.archivesBaseName}/blob/master/LICENSE.md"
distribution "repo"
}
}
developers {
developer {
id "brainstone"
name "The_BrainStone"
email "yannick@tedworld.de"
roles {
role "developer"
role "development leader"
role "team leader"
}
}
developer {
id "shawn_ian"
name "shawn_ian"
roles {
role "former developer"
}
}
}
}
}
}
// ==========================================
//
// ____ __ _
// / __ \ / /__ __ ____ _ (_)____ _____
// / /_/ // // / / // __ `// // __ \ / ___/
// / ____// // /_/ // /_/ // // / / /(__ )
// /_/ /_/ \__,_/ \__, //_//_/ /_//____/
// /____/
//
// ==========================================
buildscript {
repositories {
mavenCentral()
maven {
name "Gradle-Plugins"
url "https://plugins.gradle.org/m2/"
}
maven {
name "TimeConqueror's Maven"
url "https://repo.repsy.io/mvn/timeconqueror/mc/"
}
maven {
name "forge"
url "https://files.minecraftforge.net/maven"
}
maven {
name "sponge"
url "https://repo.spongepowered.org/maven"
}
}
dependencies {
classpath "com.xlson.groovycsv:groovycsv:1.3"
classpath "com.google.guava:guava:29.0-jre"
classpath "com.github.sghill.gradle:distribution-sha-plugin:0.4.0"
classpath "io.franzbecker:gradle-lombok:4.0.0"
classpath "com.github.ben-manes:gradle-versions-plugin:0.27.0"
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.0"
classpath "gradle.plugin.org.myire:munge:1.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
classpath "io.freefair.gradle:maven-plugin:5.3.0"
if (!project.hasProperty("enableShadow") || Boolean.parseBoolean(enableShadow.toString()))
classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2"
if ((type == "sponge") || (type == "spongeforge"))
classpath "gradle.plugin.org.spongepowered:spongegradle:0.9.0"
if ((type == "forge") || (type == "spongeforge")) {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.0.187-patched'
if ((project.hasProperty("curseForgeApiKey") || (System.env.curseForgeApiKey != null)) && project.hasProperty("curseforge_project_id"))
classpath "gradle.plugin.com.matthewprenger:CurseGradle:1.4.0"
}
if ((type == "spongeforge") && (project.hasProperty("useMixins") && Boolean.parseBoolean(useMixins.toString())))
classpath "org.spongepowered:mixingradle:0.7-SNAPSHOT"
if (
(
(!project.hasProperty("isOnOre") && ((type == "sponge") || (type == "forge") || (type == "spongeforge"))) ||
(project.hasProperty("isOnOre") && ((isOnOre == "auto") || Boolean.parseBoolean(isOnOre.toString())))
) ||
(project.hasProperty("devUpdateWebHook") || (System.env.devUpdateWebHook != null)) ||
(project.hasProperty("releaseWebHook") || (System.env.releaseWebHook != null))) {
classpath "gradle.plugin.com.github.dosmike:PluginPublisher:1.2.1"
}
}
}
allprojects {
buildscript {
repositories {
mavenCentral()
maven {
name "Gradle-Plugins"
url "https://plugins.gradle.org/m2/"
}
maven {
name "TimeConqueror's Maven"
url "https://repo.repsy.io/mvn/timeconqueror/mc/"
}
maven {
name "forge"
url "https://files.minecraftforge.net/maven"
}
maven {
name "sponge"
url "https://repo.spongepowered.org/maven"
}
}
}
}
apply plugin: com.github.sghill.gradle.DistributionShaPlugin
apply plugin: io.franzbecker.gradle.lombok.LombokPlugin
apply plugin: com.github.benmanes.gradle.versions.VersionsPlugin
apply plugin: com.github.spotbugs.snom.SpotBugsPlugin
apply plugin: org.myire.munge.MungePlugin
apply plugin: com.diffplug.gradle.spotless.SpotlessPlugin
apply plugin: io.freefair.gradle.plugins.maven.javadoc.JavadocLinksPlugin
if (enableShadow)
apply plugin: com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
if ((type == SPONGE) || (type == SPONGEFORGE)) {
apply plugin: org.spongepowered.gradle.meta.MetadataPlugin
apply plugin: org.spongepowered.gradle.plugin.SpongePluginPlugin
}
if ((type == FORGE) || (type == SPONGEFORGE)) {
apply plugin: net.minecraftforge.gradle.userdev.UserDevPlugin
if (project.hasProperty("curseForgeApiKey") && project.hasProperty("curseforge_project_id"))
apply plugin: com.matthewprenger.cursegradle.CurseGradlePlugin
}
if (useMixins)
apply plugin: org.spongepowered.asm.gradle.plugins.MixinGradlePlugin
if ((project.hasProperty("oreDeployApiKey") && isOnOre) ||
project.hasProperty("devUpdateWebHook") ||
project.hasProperty("releaseWebHook"))
apply plugin: de.dosmike.sponge.pluginpublisher.gradle.PluginPublisherPlugin
// ==============================================================================
//
// ______ ____ _ __ _
// / ____/____ ____ / __/(_)____ _ __ __ _____ ____ _ / /_ (_)____ ____
// / / / __ \ / __ \ / /_ / // __ `// / / // ___// __ `// __// // __ \ / __ \
// / /___ / /_/ // / / // __// // /_/ // /_/ // / / /_/ // /_ / // /_/ // / / /
// \____/ \____//_/ /_//_/ /_/ \__, / \__,_//_/ \__,_/ \__//_/ \____//_/ /_/
// /____/
//
// ==============================================================================
// Select Java compatibility
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.getVersionForMajor(Integer.parseInt(java_version))
Project proj = project
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
project {
name = pluginName
}
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
spotbugs {
toolVersion = spotBugs_version
effort = "max"
}
spotless {
java {
googleJavaFormat()
File headerFile = file("LICENSE-header.txt")
File rootHeaderFile = rootProject.file("LICENSE-header.txt")
if (headerFile.exists())
licenseHeaderFile headerFile
else if (rootHeaderFile.exists())
licenseHeaderFile rootHeaderFile
}
}
sourceSets {
if (hasApi) {
api
}
}
sourceSets.all {
configurations.getByName(runtimeClasspathConfigurationName) {
attributes.attribute(Attribute.of("org.gradle.jvm.environment", String), "standard-jvm")
}
configurations.getByName(compileClasspathConfigurationName) {
attributes.attribute(Attribute.of("org.gradle.jvm.environment", String), "standard-jvm")
}
}
configurations {
codacy
if (enableShadow) {
shadowRelocate
shadow.extendsFrom shadowRelocate
api.extendsFrom shadow
}
testImplementation {
transitive = true
}
spotbugsStylesheets {
transitive = false
}
}
if (hasApi && apiDependsOnPlatform && ((type == FORGE) || (type == SPONGEFORGE))) {
configurations {
apiImplementation {
extendsFrom minecraft
transitive = true
}
}
}
repositories {
// Limited repos
maven {
name "CurseMaven"
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
name "Nukkit"
url "https://repo.opencollab.dev/maven-snapshots"
content {
includeGroup "cn.nukkit"
includeGroup "com.nukkitx"
}
}
// Standard repos
mavenCentral()
// Custom repos
maven {
name "Aura Dev"
url "https://maven.aura-dev.team/repository/auradev-snapshots/"
}
maven {
name "BungeeCord"
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
name "Velocity"
url "https://repo.velocitypowered.com/snapshots/"
}
maven {
name "Spigot"
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
}
maven {
name "Sponge"
url "https://repo.spongepowered.org/maven"
}
maven {
name "CodeMC"
url "https://repo.codemc.org/repository/maven-public"
}
removeIf {
it.name.startsWith('MavenLocal')
}
}
dependencies {
if (hasApi) {
implementation sourceSets.api.output
apiCompileOnly "org.projectlombok:lombok:${lombok_version}"
apiAnnotationProcessor "org.projectlombok:lombok:${lombok_version}"
}
if (type == BUNGEECORD) {
api "net.md-5:bungeecord-api:${bungeecoord_version}"
if (hasApi && apiDependsOnPlatform)
apiImplementation "net.md-5:bungeecord-api:${bungeecoord_version}"
}
if (type == VELOCITY) {
api "com.velocitypowered:velocity-api:${velocity_version}"
if (hasApi && apiDependsOnPlatform)
apiImplementation "com.velocitypowered:velocity-api:${velocity_version}"
}
if (type == SPIGOT) {
api "org.spigotmc:spigot-api:${spigot_version}"
if (hasApi && apiDependsOnPlatform)
apiImplementation "org.spigotmc:spigot-api:${spigot_version}"
}
if ((type == SPONGE) || (type == SPONGEFORGE)) {
api "org.spongepowered:spongeapi:${sponge_version}"
annotationProcessor "org.spongepowered:spongeapi:${sponge_version}"
if (hasApi && apiDependsOnPlatform) {
apiImplementation "org.spongepowered:spongeapi:${sponge_version}"
apiAnnotationProcessor "org.spongepowered:spongeapi:${sponge_version}"
}
}
if ((type == FORGE) || (type == SPONGEFORGE)) {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// API dependency handled through configurations
}
if (type == NUKKIT) {
api "cn.nukkit:nukkit:${nukkit_version}"
if (hasApi && apiDependsOnPlatform)
apiImplementation "cn.nukkit:nukkit:${nukkit_version}"
}
if (useStats) {
if ((type == SPONGE) || (type == SPONGEFORGE)) {
shadow "org.bstats:${bStatsName}:${bStats_version}"
} else {
shadowRelocate "org.bstats:${bStatsName}:${bStats_version}"
}
}
if (useMixins) {
api "org.spongepowered:mixin:${mixin_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
if (hasApi && apiDependsOnPlatform) {
apiImplementation "org.spongepowered:mixin:${mixin_version}"
apiAnnotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
}
}
compileOnly "com.github.spotbugs:spotbugs-annotations:${spotBugs_version}"
spotbugsStylesheets "com.github.spotbugs:spotbugs:${spotBugs_version}"
if (hasApi)
apiCompileOnly "com.github.spotbugs:spotbugs-annotations:${spotBugs_version}"
testImplementation "junit:junit:4.12"
testCompileOnly "com.github.spotbugs:spotbugs-annotations:${spotBugs_version}"
if (project.hasProperty("codacyApiToken"))
codacy "com.codacy:codacy-coverage-reporter:6.0.7"
if (enableMockTesting) {
testImplementation "org.mockito:mockito-core:${mockito_version}"
testImplementation "org.powermock:powermock-api-mockito2:${powerMock_version}"
testImplementation "org.powermock:powermock-module-junit4:${powerMock_version}"
}
}
if ((type == SPONGE) || (type == SPONGEFORGE)) {
sponge {
plugin {
meta {
def baseProject = useRootValues? rootProject : project
id = baseProject.pluginId
name = baseProject.pluginName
version = baseProject.version
description = baseProject.description
}
}
}
compileJava {
outputs.upToDateWhen { false }
doFirst { println() }
}
}
if ((type == FORGE) || (type == SPONGEFORGE)) {
minecraft {
mappings channel: proj.mapping_version.split('_', 2)[0], version: proj.mapping_version.split('_', 2)[1]
//makeObfSourceJar = false
//useDepAts = true
//clientJvmArgs += "-Xmx2G"
//serverJvmArgs += "-Xmx2G"
if (Integer.parseInt(minecraft_version.split('\\.')[1]) >= 13) {
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
} else {
def ats = fileTree(dir: 'src/main/resources', include: '*_at.cfg')
if (!ats.empty) accessTransformer = ats.first()
}
runs {
client {
workingDirectory project.file('run')
if (useMixins) args '--mixin', "mixins.${pluginId}.json".toString()
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
"${pluginId}" {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
if (useMixins) args '--mixin', "mixins.${pluginId}.json".toString()
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
"${pluginId}" {
source sourceSets.main
}
}
}
if (Integer.parseInt(minecraft_version.split('\\.')[1]) >= 14) {
data {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
args '--mod', pluginId, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
"${pluginId}" {
source sourceSets.main
}
}
}
}
}
}
}
if (useMixins) {
mixin {
add sourceSets.main, "mixins.${pluginId}.refmap.json"
}
}
lombok {
version = lombok_version
sha256 = lombok_hash
}
processResources {
def baseProject = useRootValues? rootProject : project
// this will ensure that this task is redone when the versions change.
inputs.property "pluginId", baseProject.pluginId
inputs.property "pluginName", baseProject.pluginName
inputs.property "version", baseProject.version
inputs.property "group", baseProject.group
inputs.property "description", baseProject.description
inputs.property "buildNum", baseProject.buildNum
inputs.property "buildType", baseProject.buildType
inputs.property "minecraftVersion", baseProject.minecraft_version
from(sourceSets.main.resources.srcDirs) {
exclude "lang"
exclude "assets/*/lang"
exclude "*.conf"
exclude pngPatterns
exclude "**/*.ogg"
exclude "**/*.nbt"
expand(
"id": baseProject.pluginId,
"name": baseProject.pluginName,
"version": baseProject.version,
"group": baseProject.group,
"description": baseProject.description,
"build": baseProject.buildNum,
"buildType": baseProject.buildType,
"minecraftVersion": baseProject.minecraft_version
)
}
rename "(.+_at.cfg)", "META-INF/\$1"
// Minify json resources
doLast {
fileTree(dir: outputs.files.asPath, includes: jsonPatterns).each {
File file -> file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}
task processSources (type: Sync) {
def baseProject = useRootValues? rootProject : project
inputs.property "pluginId", baseProject.pluginId
inputs.property "pluginName", baseProject.pluginName
inputs.property "version", baseProject.version
inputs.property "group", baseProject.group
inputs.property "description", baseProject.description
inputs.property "buildNum", baseProject.buildNum
inputs.property "buildType", baseProject.buildType
inputs.property "minecraftVersion", baseProject.minecraft_version
ext.outputDir = file("$buildDir/generated-src/main")
from sourceSets.main.allSource
into outputDir
filter (ReplaceTokens, tokens: [
"id": baseProject.pluginId,
"name": baseProject.pluginName,
"version": baseProject.version,
"group": baseProject.group,
"description": baseProject.description,
"build": baseProject.buildNum,
"buildType": baseProject.buildType,
"minecraftVersion": baseProject.minecraft_version
])
}
if (hasApi) {
task processApiSources (type: Sync) {
def baseProject = useRootValues? rootProject : project
inputs.property "pluginId", baseProject.pluginId
inputs.property "pluginName", baseProject.pluginName
inputs.property "version", baseProject.version
inputs.property "group", baseProject.group
inputs.property "description", baseProject.description
inputs.property "buildNum", baseProject.buildNum
inputs.property "buildType", baseProject.buildType
inputs.property "minecraftVersion", baseProject.minecraft_version
ext.outputDir = file("$buildDir/generated-src/api")
from sourceSets.api.allSource
into outputDir
filter (ReplaceTokens, tokens: [
"id": baseProject.pluginId,
"name": baseProject.pluginName,
"version": baseProject.version,
"group": baseProject.group,
"description": baseProject.description,
"build": baseProject.buildNum,
"buildType": baseProject.buildType,
"minecraftVersion": baseProject.minecraft_version
])
}
}
task processTestSources (type: Sync) {
def baseProject = useRootValues? rootProject : project
inputs.property "pluginId", baseProject.pluginId
inputs.property "pluginName", baseProject.pluginName
inputs.property "version", baseProject.version
inputs.property "group", baseProject.group
inputs.property "description", baseProject.description
inputs.property "buildNum", baseProject.buildNum
inputs.property "buildType", baseProject.buildType
inputs.property "minecraftVersion", baseProject.minecraft_version
inputs.property "testSecrets", baseProject.testSecrets
ext.outputDir = file("$buildDir/generated-src/test")
from sourceSets.test.allSource
into outputDir
filter (ReplaceTokens, tokens: [
"id": baseProject.pluginId,
"name": baseProject.pluginName,
"version": baseProject.version,
"group": baseProject.group,
"description": baseProject.description,
"build": baseProject.buildNum,
"buildType": baseProject.buildType,
"minecraftVersion": baseProject.minecraft_version,