· 6 years ago · Dec 02, 2019, 03:10 PM
1buildscript {
2
3 repositories {
4
5 jcenter()
6
7 maven {
8
9 name = 'forge'
10
11 url = 'http://files.minecraftforge.net/maven'
12
13 }
14
15 maven {
16
17 name = 'gradle'
18
19 url 'https://plugins.gradle.org/m2/'
20
21 }
22
23 maven {
24
25 name = 'sonatype'
26
27 url = 'https://oss.sonatype.org/content/groups/public'
28
29 }
30
31 }
32
33 dependencies {
34
35 classpath "net.minecraftforge.gradle:${project.fg_version}"
36
37// classpath 'org.junit.platform:junit-platform-gradle-plugin:1.2.+'
38
39// classpath 'com.jaredsburrows:gradle-checker-framework-plugin:0.2.1'
40
41 }
42
43}
44
45
46
47plugins {
48
49//id 'com.github.spotbugs' version '1.6.2'
50
51 id 'com.matthewprenger.cursegradle' version '1.1.0'
52
53 id "org.sonarqube" version "2.6"
54
55}
56
57
58
59apply plugin: 'net.minecraftforge.gradle.forge'
60
61apply plugin: 'com.matthewprenger.cursegradle'
62
63apply plugin: 'maven-publish'
64
65apply plugin: 'org.sonarqube'
66
67//apply plugin: 'org.junit.platform.gradle.plugin'
68
69apply plugin: 'jacoco'
70
71//apply plugin: 'com.github.spotbugs'
72
73//apply plugin: 'com.jaredsburrows.checkerframework'
74
75
76
77repositories {
78
79 mavenLocal()
80
81 mavenCentral()
82
83}
84
85
86
87dependencies {
88
89 testCompile('org.junit.jupiter:junit-jupiter-api:5.2.+')
90
91// Only used for JUnit Platform Launcher 1.2.0 and earlier
92
93//testCompile('org.junit.platform:junit-platform-launcher:1.2.+')
94
95 testRuntime('org.junit.jupiter:junit-jupiter-engine:5.2.+')
96
97 testCompile('org.mockito:mockito-core:2.+')
98
99}
100
101
102
103// TODO: Fix this for JUnit Platform Launcher 1.3
104
105project.afterEvaluate {
106
107// def junitPlatformTestTask = project.tasks.getByName('junitPlatformTest')
108
109
110
111 // configure jacoco to analyze the junitPlatformTest task
112
113 jacoco {
114
115 // this tool version is compatible with
116
117 toolVersion = '0.8.1'
118
119// applyTo junitPlatformTestTask
120
121 }
122
123
124
125 // create junit platform jacoco task
126
127 project.task(type: JacocoReport, "junitPlatformJacocoReport",
128
129 {
130
131 sourceDirectories = files("./src/main")
132
133 classDirectories = files("$buildDir/classes/main")
134
135// executionData junitPlatformTestTask
136
137 })
138
139}
140
141
142
143// Only used for JUnit Platform Launcher 1.2.0 and earlier
144
145/*
146
147junitPlatform {
148
149 // platformVersion '1.2.0'
150
151 // logManager 'org.apache.logging.log4j.jul.LogManager'
152
153 reportsDir file("${project.buildDir}/test-results/junit-platform")
154
155 // enableStandardTestTask true
156
157 // selectors (optional)
158
159 // filters (optional)
160
161}
162
163*/
164
165
166
167/*
168
169spotbugs {
170
171 toolVersion = '3.1.6'
172
173}
174
175*/
176
177
178
179tasks.withType(JavaCompile) {
180
181 options.encoding = 'UTF-8'
182
183 options.compilerArgs = [
184
185 '-Xlint:deprecation', // deprecation, rawtypes, cast, unchecked, all
186
187// '-Xdiags:verbose',
188
189// '-Werror'
190
191 ]
192
193}
194
195
196
197javadoc {
198
199 failOnError = false
200
201}
202
203
204
205//ext.short_version = '1.0.0'
206
207//ext.short_version = getVersion('VERSION', <path to file containing version string)
208
209ext.short_version = getVersion('VERSION', getModFile())
210
211version = mc_version + '-' + short_version
212
213ext.display_version = short_version
214
215
216
217def llibrary_version = getVersion('LLIBRARY_VERSION', getModFile())
218
219
220
221if ((System.getenv('BUILD_NUMBER')) || (System.getenv('TRAVIS_BUILD_NUMBER')) || (System.getenv('CIRCLE_BUILD_NUM'))) {
222
223 version += '.' +getBuildNumber()
224
225 display_version += '.' + getBuildNumber()
226
227}
228
229
230
231String getBuildNumber() {
232
233 return System.getenv('BUILD_NUMBER') ? System.getenv('BUILD_NUMBER') : System.getenv('TRAVIS_BUILD_NUMBER') ? System.getenv('TRAVIS_BUILD_NUMBER') : System.getenv('CIRCLE_BUILD_NUM') ? System.getenv('CIRCLE_BUILD_NUM') : '0';
234
235}
236
237
238
239sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
240
241
242
243eclipse.project {
244
245 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
246
247 natures 'org.eclipse.buildship.core.gradleprojectnature'
248
249}
250
251
252
253class Secrets {
254
255 def data = null
256
257
258
259 def getProperty(String key) {
260
261 return data ? data[key] : ''
262
263 }
264
265}
266
267
268
269import groovy.json.JsonSlurper
270
271
272
273def secretFile
274
275if (System.getenv('SECRET_FILE')) {
276
277 secretFile = file System.getenv().SECRET_FILE
278
279} else {
280
281 secretFile = file 'secret.json'
282
283}
284
285
286
287ext.secret = new Secrets()
288
289if (secretFile.exists()) {
290
291 secretFile.withReader {
292
293 project.secret.data = new JsonSlurper().parse it
294
295 }
296
297}
298
299
300
301minecraft {
302
303 version = project.forge_mc_version + '-' + project.forge_version
304
305 runDir = 'run'
306
307 mappings = project.mcp_mappings
308
309
310
311 replace '@MOD_VERSION@', project.short_version
312
313
314
315 if ((project.hasProperty('signSHA1')) && (project.hasProperty('doSignJar'))) {
316
317 replace '@FINGERPRINT@', project.findProperty('signSHA1')
318
319 } else {
320
321 replace '@FINGERPRINT@', ''
322
323 }
324
325
326
327 if (project.hasProperty('coreplugin')) {
328
329 clientJvmArgs += '-Dfml.coreMods.load=' + project.coreplugin
330
331 serverJvmArgs += '-Dfml.coreMods.load=' + project.coreplugin
332
333 }
334
335
336
337 if (project.hasProperty('mc_username')) {
338
339 clientRunArgs += ['--username', project.mc_username]
340
341 if (project.hasProperty('mc_password')) {
342
343 clientRunArgs += ['--password', project.mc_password]
344
345 }
346
347 }
348
349 if (project.hasProperty('mc_uuid')) {
350
351 clientRunArgs += ['--uuid', project.mc_uuid]
352
353 }
354
355
356
357 // disable server gui
358
359 if (project.hasProperty('server_nogui')) {
360
361 serverRunArgs += 'nogui'
362
363 }
364
365
366
367 // skip the screen to confirm that you want to load a world with missing registry entries
368
369 if (project.hasProperty('doNotBackup')) {
370
371 serverJvmArgs += '-Dfml.doNotBackup=true'
372
373 clientJvmArgs += '-Dfml.doNotBackup=true'
374
375 }
376
377
378
379 // skip having to confirm on server
380
381 if (project.hasProperty('queryResultConfirm')) {
382
383 serverJvmArgs += '-Dfml.queryResult=confirm'
384
385 }
386
387
388
389 // skip jansi warnings in the log
390
391 if (project.hasProperty('skipJansi')) {
392
393 serverJvmArgs += '-Dlog4j.skipJansi=true'
394
395 clientJvmArgs += '-Dlog4j.skipJansi=true'
396
397 }
398
399
400
401 if (project.hasProperty('client_args')) {
402
403 clientJvmArgs += project.client_args
404
405 }
406
407 if (project.hasProperty('server_args')) {
408
409 serverJvmArgs += project.server_args
410
411 }
412
413
414
415 if (!project.hasProperty('doSourceJar')) {
416
417 makeObfSourceJar = false
418
419 }
420
421 if (project.hasProperty('depHasATs')) {
422
423 useDepAts = ${depHasATs}
424
425 }
426
427}
428
429
430
431repositories {
432
433 maven {
434
435 name 'MMD'
436
437 url 'https://maven.mcmoddev.com/'
438
439 }
440
441 maven {
442
443 name 'JEI'
444
445 url = "http://dvs1.progwml6.com/files/maven"
446
447 }
448
449 maven { // HWYLA
450
451 name 'tehnut'
452
453 url 'http://tehnut.info/maven/'
454
455 }
456
457}
458
459
460
461dependencies {
462
463 deobfProvided "mezz.jei:jei_1.12.2:4.9.1.187:api"
464
465 runtime "mezz.jei:jei_1.12.2:4.9.1.187"
466
467 deobfCompile "net.ilexiconn:llibrary:${llibrary_version}-1.12.2"
468
469 deobfCompile "mcp.mobius.waila:Hwyla:1.8.26-B41_1.12.2"
470
471}
472
473
474
475processResources {
476
477 inputs.property 'version', project.short_version
478
479 inputs.property 'mcversion', project.minecraft.version
480
481
482
483 from (sourceSets.main.resources.srcDirs) {
484
485 include 'mcmod.info'
486
487 expand 'version': project.short_version, 'mcversion': project.minecraft.version
488
489 }
490
491
492
493 from (sourceSets.main.resources.srcDirs) {
494
495 exclude 'mcmod.info'
496
497 }
498
499
500
501 rename '(.+_at.cfg)', 'META-INF/$1'
502
503}
504
505
506
507jar {
508
509 //from sourceSets.api.output
510
511 //from sourceSets.main.output
512
513
514
515 manifest {
516
517 attributes 'Maven-Artifact' : "${project.group}:${project.archivesBaseName}:${project.version}"
518
519 attributes 'Timestamp' : System.currentTimeMillis()
520
521 if (project.hasProperty('coreplugin')) {
522
523 attributes 'FMLCorePluginContainsFMLMod': 'true'
524
525 attributes 'FMLCorePlugin': ${coreplugin}
526
527 }
528
529 if (project.hasProperty('at_file')) {
530
531 attributes 'FMLAT' : ${at_file}
532
533 }
534
535 }
536
537}
538
539
540
541task apiJar(type: Jar) {
542
543 classifier = 'apiClasses'
544
545 from apiClasses
546
547 // from sourceSets.api.output
548
549}
550
551
552
553task deobfJar(type: Jar) {
554
555 classifier = 'deobf'
556
557 from sourceSets.main.output
558
559}
560
561
562
563task javadocJar(type: Jar, dependsOn: javadoc) {
564
565 classifier = 'javadoc'
566
567 from javadoc.getDestinationDir()
568
569}
570
571
572
573task signJar(type: SignJar, dependsOn: reobfJar) {
574
575 onlyIf {
576
577 project.hasProperty('keyStore')
578
579 }
580
581
582
583 inputFile = jar.archivePath
584
585 outputFile = jar.archivePath
586
587
588
589 keyStore = project.findProperty('keyStore')
590
591 alias = project.findProperty('keyStoreAlias')
592
593 storePass = project.findProperty('keyStorePass')
594
595 keyPass = project.findProperty('keyStoreKeyPass')
596
597}
598
599
600
601if (project.hasProperty('doSignJar')) {
602
603 build.dependsOn signJar
604
605}
606
607
608
609artifacts {
610
611 if (project.hasProperty('doAPIJar')) {
612
613 archives apiJar
614
615 }
616
617 if (project.hasProperty('doDeobfJar')) {
618
619 archives deobfJar
620
621 }
622
623 if (project.hasProperty('doSourceJar')) {
624
625 archives sourceJar
626
627 }
628
629 if (project.hasProperty('doJavadocJar')) {
630
631 archives javadocJar
632
633 }
634
635}
636
637
638
639publishing {
640
641 publications {
642
643 mavenJava(MavenPublication) {
644
645 groupId project.group
646
647 artifactId project.archivesBaseName
648
649 version project.version
650
651 from components.java
652
653 if (project.hasProperty('doSourceJar')) {
654
655 artifact sourceJar {
656
657 classifier 'sources'
658
659 }
660
661 }
662
663 if (project.hasProperty('doAPIJar')) {
664
665 artifact apiJar {
666
667 classifier 'api'
668
669 }
670
671 }
672
673 if (project.hasProperty('doDeobfJar')) {
674
675 artifact deobfJar {
676
677 classifier 'deobf'
678
679 }
680
681 }
682
683 if (project.hasProperty('doJavadocJar')) {
684
685 artifact javadocJar {
686
687 classifier 'javadoc'
688
689 }
690
691 }
692
693 }
694
695 }
696
697 repositories {
698
699 maven {
700
701 credentials {
702
703 username secret.username
704
705 password secret.password
706
707 }
708
709 url secret.url
710
711 }
712
713 }
714
715}
716
717
718
719curseforge {
720
721 if (project.hasProperty('cf_project_id') && project.hasProperty('cf_release_type') && project.hasProperty('cf_changelog_filename') &&
722
723 ((project.cf_release_type == 'alpha') || (project.cf_release_type == 'beta') || (project.cf_release_type == 'release'))) {
724
725 apiKey = secret.curseforgeAPIKey
726
727 def versions = "${cf_versions}".split(', ')
728
729 project {
730
731 id = "${cf_project_id}"
732
733 // A list of changes for the current build. This can be a String or a File. If a file is set, its contents will be used. This is a required field.
734
735 changelog = file(project.cf_changelog_filename)
736
737 // The type of changelog. This can be: text, html, or markdown. The default is text.
738
739 changelogType = project.cf_changelog_type
740
741 releaseType = project.cf_release_type
742
743 versions.each {
744
745 addGameVersion "${it}"
746
747 }
748
749 mainArtifact(jar) {
750
751 //displayName = "$project.description $project.display_version"
752
753 if (project.hasProperty('curse_requirements') || project.hasProperty('curse_optionals') || project.hasProperty('curse_embeddeds') || project.hasProperty('curse_tools') || project.hasProperty('curse_incompatibles') || project.hasProperty('curse_includes')) {
754
755 relations {
756
757 if (project.hasProperty('curse_requirements')) {
758
759 def requirements = "${curse_requirements}".split(', ')
760
761 requirements.each {
762
763 requiredLibrary "${it}"
764
765 }
766
767 }
768
769 if (project.hasProperty('curse_optionals')) {
770
771 def optionals = "${curse_optionals}".split(', ')
772
773 optionals.each {
774
775 optionalLibrary "${it}"
776
777 }
778
779 }
780
781 if (project.hasProperty('curse_embeddeds')) {
782
783 def embeddeds = "${curse_embeddeds}".split(', ')
784
785 embeddeds.each {
786
787 embeddedLibrary "${it}"
788
789 }
790
791 }
792
793 if (project.hasProperty('curse_tools')) {
794
795 def tools = "${curse_tools}".split(', ')
796
797 tools.each {
798
799 tool "${it}"
800
801 }
802
803 }
804
805 if (project.hasProperty('curse_incompatibles')) {
806
807 def incompatibles = "${curse_incompatibles}".split(', ')
808
809 incompatibles.each {
810
811 incompatible "${it}"
812
813 }
814
815 }
816
817 if (project.hasProperty('curse_includes')) {
818
819 def includes = "${curse_includes}".split(', ')
820
821 includeds.each {
822
823 include "${it}"
824
825 }
826
827 }
828
829 }
830
831 }
832
833 }
834
835 if (project.hasProperty('doAPIJar')) {
836
837 addArtifact(apiJar) {
838
839 //displayName = "$project.description $project.display_version API"
840
841 }
842
843 }
844
845 if (project.hasProperty('doSourceJar')) {
846
847 addArtifact(sourceJar) {
848
849 //displayName = "$project.description $project.display_version Sources"
850
851 }
852
853 }
854
855 if (project.hasProperty('doDeobfJar')) {
856
857 addArtifact(deobfJar) {
858
859 //displayName = "$project.description $project.display_version Development"
860
861 }
862
863 }
864
865 if (project.hasProperty('doJavadocJar')) {
866
867 addArtifact(javadocJar) {
868
869 //displayName = "$project.description $project.display_version Javadoc"
870
871 }
872
873 }
874
875 }
876
877 }
878
879}
880
881
882
883sonarqube {
884
885 properties {
886
887 property 'sonar.host.url', secret.sonarHost
888
889 property 'sonar.organization', secret.sonarOrganization
890
891 property 'sonar.login', secret.sonarToken
892
893 property 'sonar.projectKey', secret.sonarKey
894
895 // property 'sonar.projectName', project.archivesBaseName
896
897 // property 'sonar.branch.name', 'master-1.12.2'
898
899 // property 'sonar.branch.target', ''
900
901 //property 'sonar.junit.reportPaths', "${project.buildDir}/test-results/junit-platform/*.xml"
902
903 //property 'sonar.jacoco.reportPaths', "${project.buildDir}/jacoco/junitPlatformTest.exec"
904
905 }
906
907}
908
909
910
911String getModFile() {
912
913 String path = ''
914
915 FileTree tree = fileTree(dir: 'src/main/java')
916
917 tree.include '**/*.java'
918
919 tree.visit { element ->
920
921 if (element.file.isFile()) {
922
923 element.file.eachLine { String s ->
924
925 s = s.trim()
926
927 if (s.startsWith('@Mod(')) {
928
929 path = "src/main/java/$element.relativePath"
930
931 }
932
933 }
934
935 }
936
937 }
938
939 return path
940
941}
942
943
944
945String getVersion(String type, String mod_file) {
946
947 String major = '0'
948
949 String revision = '0'
950
951 String patch = '0'
952
953 File file = file(mod_file)
954
955 def prefix = ~/^(?:public|protected|private) static final String $type = ".*$/
956
957 file.eachLine { String s ->
958
959 s = s.trim()
960
961 if (s ==~ prefix || prefix.matcher(s).matches()) {
962
963 String[] bits = s.split("=")
964
965 String interesting = bits[1].trim()
966
967 interesting = interesting.substring(1, interesting.length() - 2)
968
969 String[] pts = interesting.trim().split("\\.")
970
971
972
973 major = pts[0] ?: '0'
974
975 revision = pts[1] ?: '0'
976
977 patch = pts[2] ?: '0'
978
979 }
980
981 }
982
983 return "$major.$revision.$patch"
984
985}