-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
848 lines (768 loc) · 29.2 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
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
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
name = 'forge'
url = 'https://maven.minecraftforge.net'
}
maven {
name = 'gradle'
url 'https://plugins.gradle.org/m2/'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public'
}
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: project.fg_version
//classpath group: 'com.jaredsburrows', name: 'gradle-checker-framework-plugin', version: '0.2.2'
}
}
plugins {
id 'com.github.spotbugs' version '1.6.9' // 4.0 or later
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'org.sonarqube' version '2.8'
//id 'org.junit.platform.gradle.plugin' version '1.2.0'
id 'maven-publish'
id 'jacoco'
id 'checkstyle' // 2.7 or later
}
apply plugin: 'net.minecraftforge.gradle.forge' // FG2.x
//apply plugin: 'forge' // FG1.x
//apply plugin: 'com.jaredsburrows.checkerframework'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'pmd'
project.afterEvaluate {
//final def junitPlatformTestTask = project.tasks.getByName('junitPlatformTest')
// configure jacoco to analyze the junitPlatformTest task
jacoco {
// this tool version is compatible with
toolVersion = '0.8.3'
// Not needed with new way
//if (GradleVersion.current() < GradleVersion.version('4.6')) {
//applyTo junitPlatformTestTask
//}}
}
// create junit platform jacoco task
project.task(type: JacocoReport, 'junitPlatformJacocoReport',
{
if (GradleVersion.current() >= GradleVersion.version('5.0')) {
getSourceDirectories().from(files('./src/main'))
getClassDirectories().from(files("${project.buildDir}/classes/main"))
} else {
sourceDirectories = files('./src/main')
classDirectories = files("${project.buildDir}/classes/main")
}
// Not needed with new way
//if (GradleVersion.current() < GradleVersion.version('4.6')) {
// executionData junitPlatformTestTask
//}
})
}
// Only works with JUnit Platform Launcher 1.2.0 and earlier
/*
if (GradleVersion.current() < GradleVersion.version('4.6')) {
junitPlatform {
// platformVersion '1.2.0'
// logManager 'org.apache.logging.log4j.jul.LogManager'
reportsDir file("${project.buildDir}/test-results/junit-platform")
// enableStandardTestTask true
// selectors (optional)
// filters (optional)
}
}
*/
if (GradleVersion.current() >= GradleVersion.version('4.0')) {
spotbugs {
ignoreFailures = true
toolVersion = '3.1.6'
effort = 'max'
reportLevel = 'low'
//includeFilter = file("$rootProject.projectDir/config/spotbugs-filter.xml")
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}
}
if (GradleVersion.current() >= GradleVersion.version('2.7')) {
checkstyle {
ignoreFailures = true
toolVersion = '8.20' // 5.7 is default
showViolations = false
}
}
pmd {
consoleOutput = false
ignoreFailures = true
sourceSets = [sourceSets.main]
reportsDir = file("$project.buildDir/reports/pmd")
rulePriority = 5
ruleSets = [
'java-android',
'java-basic',
'java-braces',
'java-clone',
'java-codesize',
'java-comments',
'java-controversial',
'java-coupling',
'java-design',
'java-empty',
'java-finalizers',
'java-imports',
'java-j2ee',
'java-javabeans',
'java-junit',
'java-logging-jakarta-commons',
'java-logging-java',
// 'java-metrics', // Upsets 5.8.1
'java-migrating',
'java-migrating_to_junit4',
'java-naming',
'java-optimizations',
// 'java-quickstart', // 6.x
'java-strictexception',
'java-strings',
'java-sunsecure',
'java-typeresolution',
'java-unnecessary',
'java-unusedcode'
]
toolVersion = '5.8.1'; // 6.19.0
if (GradleVersion.current() >= GradleVersion.version('5.6')) {
// incrementalAnalysis = true // Requires PMD 6.0.0 or newer
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs = [
'-Xlint:deprecation', // deprecation, rawtypes, cast, unchecked, all
//'-Xdiags:verbose',
//'-Werror'
]
compileJava.options.compilerArgs += '-proc:none'
}
tasks.withType(Test) {
compileTestJava.options.compilerArgs += '-proc:none'
}
javadoc {
failOnError = false
}
import org.gradle.util.GradleVersion
test {
if (GradleVersion.current() >= GradleVersion.version('4.6')) {
useJUnitPlatform()
/*
useJUnitPlatform {
includeTags 'fast', 'smoke & feature-a'
//excludeTags 'slow', 'ci'
includeEngines 'junit-jupiter'
//excludeEngines 'junit-vintage'
}
*/
}
}
//project.ext.short_version = '1.0.0'
//ext.short_version = getModVersion('VERSION', <path to file containing version string)
project.ext.short_version = getModVersion('VERSION')
version = (project.hasProperty('mc_version') ? project.mc_version : project.forge_mc_version) + '-' + short_version
project.ext.display_version = short_version
if ((System.getenv('BUILD_NUMBER')) || (System.getenv('TRAVIS_BUILD_NUMBER')) || (System.getenv('CIRCLE_BUILD_NUM'))) {
version += '.' + buildNumber
display_version += '.' + buildNumber
}
static String getBuildNumber() {
return System.getenv('BUILD_NUMBER') ?: System.getenv('TRAVIS_BUILD_NUMBER') ?: System.getenv('CIRCLE_BUILD_NUM') ?: '0'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
eclipse.project {
buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
natures 'org.eclipse.buildship.core.gradleprojectnature'
}
idea.module {
downloadJavadoc = true
//inheritOutputDirs = true
}
class Secrets {
Map m_data = null
final String getProperty(final String key) {
return (m_data && (m_data[key] != null)) ? m_data[key] : ''
}
}
final def secretFile
if (System.getenv('SECRET_FILE')) {
secretFile = file System.getenv().SECRET_FILE
} else {
secretFile = file 'secret.json'
}
import groovy.json.JsonSlurper
project.ext.secret = new Secrets()
if (secretFile.exists()) {
secretFile.withReader {
project.secret.m_data = new JsonSlurper().parse it
}
} else {
project.secret.m_data = new JsonSlurper().parseText(
'{ "username" : "' + (System.getenv('userMaven') ?: '') + '",'
+ '"password" : "' + (System.getenv('authMaven') ?: '') + '",'
+ '"url" : "' + (System.getenv('urlMaven') ?: '') + '",'
+ '"curseforgeAPIKey" : "' + (System.getenv('curse_auth') ?: '00000000-0000-0000-0000-000000000000') + '",'
+ '"sonarHost" : "' + (System.getenv('SONAR_HOST_URL') ?: 'https://sonarcloud.io') + '",'
+ '"sonarOrganization" : "' + (System.getenv('SONAR_ORGANIZATION') ?: '') + '",'
+ '"sonarToken" : "' + (System.getenv('SONAR_AUTH_TOKEN') ?: 0) + '"}'
)
}
minecraft {
version = project.forge_mc_version + '-' + project.forge_version
mappings = project.mcp_mappings_version
if (project.hasProperty('runDir')) {
runDir = project.runDir
} else if (file('../run').exists()) {
runDir = '../run'
} else {
runDir = 'run'
}
replace '@MOD_VERSION@', project.short_version
if (project.hasProperty('signSHA1') && getBooleanProperty('do_sign_jar')) {
replace '@FINGERPRINT@', project.findProperty('signSHA1')
} else {
replace '@FINGERPRINT@', ''
}
if (project.hasProperty('core_plugin')) {
clientJvmArgs += "-Dfml.coreMods.load=${project.core_plugin}"
serverJvmArgs += "-Dfml.coreMods.load=${project.core_plugin}"
}
if (project.hasProperty('mc_username')) {
clientRunArgs += ['--username', project.mc_username]
if (project.hasProperty('mc_password')) {
clientRunArgs += ['--password', project.mc_password]
}
}
if (project.hasProperty('mc_uuid')) {
clientRunArgs += ['--uuid', project.mc_uuid]
}
if (getBooleanProperty('mc_server_nogui')) {
serverRunArgs += 'nogui'
}
if (getBooleanProperty('forge_do_not_backup')) {
serverJvmArgs += '-Dfml.doNotBackup=true'
clientJvmArgs += '-Dfml.doNotBackup=true'
}
if (getBooleanProperty('forge_query_result_confirm')) {
serverJvmArgs += '-Dfml.queryResult=confirm'
}
if (getBooleanProperty('log4j_skip_jansi')) {
serverJvmArgs += '-Dlog4j.skipJansi=true'
clientJvmArgs += '-Dlog4j.skipJansi=true'
}
if (project.hasProperty('mc_resolution')) {
final def res = [
'480p': [640, 480],
'576p': [640, 576],
'720p': [1280, 720],
'1080p': [1920, 1080],
'custom': [project.findProperty('mc_custom_resolution_width'), project.findProperty('mc_custom_resolution_height')]]
final def choice = res?.get(project.mc_resolution)
if (choice != null) {
clientRunArgs += ['--width', choice[0]]
clientRunArgs += ['--height', choice[1]]
}
}
if (project.hasProperty('client_jvm_args')) {
clientJvmArgs += project.client_jvm_args
}
if (project.hasProperty('server_jvm_args')) {
serverJvmArgs += project.server_jvm_args
}
if (project.hasProperty('client_game_args')) {
clientRunArgs += project.client_game_args
}
if (project.hasProperty('server_game_args')) {
serverRunArgs += project.server_game_args
}
makeObfSourceJar = getBooleanProperty('create_source_jar')
useDepAts = getBooleanProperty('dep_has_ats')
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven {
name 'MMD'
url 'https://maven.mcmoddev.com/'
}
}
dependencies {
testCompile('org.junit.platform:junit-platform-launcher:1.5.+')
testCompile('org.junit.jupiter:junit-jupiter-api:5.5.+') // testImplementation
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.5.+') //testRuntimeOnly
if (GradleVersion.current() >= GradleVersion.version('2.13')) {
testCompileOnly 'junit:junit:4.12'
}
testRuntime 'org.junit.vintage:junit-vintage-engine:5.5.+' //testRuntimeOnly
testCompile('org.mockito:mockito-core:2.+')
testCompile('org.mockito:mockito-junit-jupiter:2.+') {
exclude group: 'org.junit.jupiter', module: 'junit-jupiter-engine'
}
if (GradleVersion.current() >= GradleVersion.version('4.6')) {
annotationProcessor group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
}
}
processResources {
inputs.property 'version', project.short_version
inputs.property 'mcversion', project.minecraft.version
from (sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version': project.short_version, 'mcversion': project.minecraft.version
}
from (sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
rename '(.+_at.cfg)', 'META-INF/$1'
}
jar {
//from sourceSets.api.output
//from sourceSets.main.output
manifest {
mainAttributes(
'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}",
'Timestamp': System.currentTimeMillis(),
'Specification-Title': 'examplemod',
'Specification-Vendor': 'mcmoddev',
'Specification-Version': '1',
'Implementation-Title': project.archivesBaseName,
'Implementation-Version': project.version,
'Implementation-Vendor' :'mcmoddev',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
'Built-On': "${project.forge_mc_version}-${project.forge_version}"
)
if (project.hasProperty('core_plugin')) {
attributes 'FMLCorePluginContainsFMLMod': 'true'
attributes 'FMLCorePlugin': project.core_plugin
}
if (project.hasProperty('mod_at_file')) {
attributes 'FMLAT': project.mod_at_file
}
if (project.hasProperty('mod_contained_deps')) {
attributes 'ContainedDeps': project.mod_contained_deps
}
}
}
task apiJar(type: Jar) {
onlyIf {
getBooleanProperty('create_api_jar')
}
description = 'Creates a JAR containing the API Classes.'
classifier = 'api'
from apiClasses
// from sourceSets.api.output
manifest {
mainAttributes(
'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:api",
'Timestamp': System.currentTimeMillis(),
'Specification-Title': 'examplemod',
'Specification-Vendor': 'mcmoddev',
'Specification-Version': '1',
'Implementation-Title': project.name + '-api',
'Implementation-Version': project.version,
'Implementation-Vendor' :'mcmoddev',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
'Built-On': "${project.forge_mc_version}-${project.forge_version}"
)
}
}
task deobfJar(type: Jar) {
onlyIf {
getBooleanProperty('create_deobf_jar')
}
description = 'Creates a JAR containing the non-obfuscated compiled code.'
classifier = 'deobf'
from sourceSets.main.output
manifest {
mainAttributes(
'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:deobf",
'Timestamp': System.currentTimeMillis(),
'Specification-Title': 'examplemod',
'Specification-Vendor': 'mcmoddev',
'Specification-Version': '1',
'Implementation-Title': project.name + '-deobf',
'Implementation-Version': project.version,
'Implementation-Vendor' :'mcmoddev',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
'Built-On': "${project.forge_mc_version}-${project.forge_version}"
)
if (project.hasProperty('mod_at_file')) {
attributes 'FMLAT': project.mod_at_file
}
if (project.hasProperty('core_plugin')) {
attributes 'FMLCorePlugin': project.core_plugin
}
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
onlyIf {
getBooleanProperty('create_javadoc_jar')
}
description = 'Creates a JAR containing the JavaDocs.'
classifier = 'javadoc'
from javadoc.getDestinationDir()
manifest.mainAttributes(
'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:javadoc",
'Timestamp': System.currentTimeMillis(),
'Implementation-Title': project.name + '-javadoc',
'Implementation-Version': project.version,
'Built-On-Java': "${System.getProperty('java.vm.version')} + (${System.getProperty('java.vm.vendor')})",
'Built-On': "${project.forge_mc_version}-${project.forge_version}"
)
}
task signJar(type: SignJar, dependsOn: reobfJar) {
onlyIf {
getBooleanProperty('do_sign_jar') &&
project.hasProperty('keyStore')
}
description = 'Sign the Main JAR'
inputFile = jar.archivePath
outputFile = jar.archivePath
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
}
task signApiJar(type: SignJar) {
onlyIf {
getBooleanProperty('create_api_jar') &&
getBooleanProperty('do_sign_jar') &&
project.hasProperty('keyStore')
}
description = 'Sign the API JAR'
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = apiJar.archivePath
outputFile = apiJar.archivePath
}
task signDeobfJar(type: SignJar) {
onlyIf {
getBooleanProperty('create_deobf_jar') &&
getBooleanProperty('do_sign_jar') &&
project.hasProperty('keyStore')
}
description = 'Sign the deobf JAR'
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = deobfJar.archivePath
outputFile = deobfJar.archivePath
}
task signSourceJar(type: SignJar) {
onlyIf {
getBooleanProperty('create_source_jar') &&
getBooleanProperty('do_sign_jar') &&
project.hasProperty('keyStore')
}
description = 'Sign the Sources JAR'
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = sourceJar.archivePath
outputFile = sourceJar.archivePath
}
task signJavadocJar(type: SignJar) {
onlyIf {
getBooleanProperty('create_javadoc_jar') &&
getBooleanProperty('do_sign_jar') &&
project.hasProperty('keyStore')
}
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = javadocJar.archivePath
outputFile = javadocJar.archivePath
}
if (getBooleanProperty('do_sign_jar')) {
build.dependsOn signJar
if (getBooleanProperty('create_api_jar')) {
build.dependsOn signApiJar
}
if (getBooleanProperty('create_deobf_jar')) {
build.dependsOn signDeobfJar
}
if (getBooleanProperty('create_source_jar')) {
build.dependsOn signSourceJar
}
if (getBooleanProperty('create_javadoc_jar')) {
build.dependsOn signJavadocJar
}
}
tasks.publish.dependsOn build
tasks.curseforge.dependsOn publish
artifacts {
if (getBooleanProperty('create_api_jar')) {
archives apiJar
}
if (getBooleanProperty('create_deobf_jar')) {
archives deobfJar
}
if (getBooleanProperty('create_source_jar')) {
archives sourceJar
}
if (getBooleanProperty('create_javadoc_jar')) {
archives javadocJar
}
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
from components.java
if (getBooleanProperty('create_source_jar')) {
artifact sourceJar {
classifier 'sources'
}
}
if (getBooleanProperty('create_api_jar')) {
artifact apiJar {
classifier 'api'
}
}
if (getBooleanProperty('create_deobf_jar')) {
artifact deobfJar {
classifier 'deobf'
}
}
if (getBooleanProperty('create_javadoc_jar')) {
artifact javadocJar {
classifier 'javadoc'
}
}
/*
pom {
name = 'Example'
description = 'An Example'
url = 'https://github.com/Examples/Example'
packaging = 'jar'
//inceptionYear = ''
licenses {
license {
name = 'GNU Lesser General Public License, Version 2.1'
url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt'
}
}
scm {
connection = 'scm:git:git://github.com/Examples/Example.git'
developerConnection = 'scm:git:git@github.com:Examples/Example.git'
url = 'https://github.com/Examples/Example'
}
issueManagement {
system = 'github'
url = 'https://github.com/Examples/Example.git/issues'
}
ciManagement {
system = 'jenkins'
url = 'https://ci.mcmoddev.com/'
}
organization {
name = 'Minecraft Mod Development'
url = 'https://mcmoddev.com/'
}
}
*/
}
}
repositories {
maven {
if ((secret.username != '') && (secret.password != '')) {
credentials {
username secret.username
password secret.password
}
}
if (secret.url != '') {
url secret.url
} else {
url "file:///${project.buildDir}/repo"
}
}
}
}
curseforge {
if (project.hasProperty('curseforge_project_id')) {
apiKey = secret.curseforgeAPIKey
project {
id = project.curseforge_project_id
if (project.hasProperty('curseforge_changelog_filename')) {
changelog = file(project.curseforge_changelog_filename)
} else {
changelog = ''
}
if (project.hasProperty('curseforge_changelog_type')) {
changelogType = project.curseforge_changelog_type
}
if ((project.hasProperty('curseforge_release_type')) && ((project.curseforge_release_type == 'alpha') || (project.curseforge_release_type == 'beta') || (project.curseforge_release_type == 'release'))) {
releaseType = project.curseforge_release_type
} else {
releaseType = 'alpha'
}
if (project.hasProperty('curseforge_versions')) {
final def versions = "${project.curseforge_versions}".split(', ')
versions.each {
addGameVersion "${it}"
}
}
mainArtifact(jar) {
if (getBooleanProperty('curseforge_use_custom_display_name')) {
displayName = "${project.name} ${project.display_version}"
}
if (project.hasProperty('curseforge_requirements') || project.hasProperty('curseforge_optionals') || project.hasProperty('curseforge_embeddeds') || project.hasProperty('curseforge_tools') || project.hasProperty('curseforge_incompatibles') || project.hasProperty('curseforge_includes')) {
relations {
if (project.hasProperty('curseforge_requirements')) {
final def requirements = "${project.curseforge_requirements}".split(', ')
requirements.each {
requiredDependency "${it}"
}
}
if (project.hasProperty('curseforge_optionals')) {
final def optionals = "${project.curseforge_optionals}".split(', ')
optionals.each {
optionalDependency "${it}"
}
}
if (project.hasProperty('curseforge_embeddeds')) {
final def embeddeds = "${project.curseforge_embeddeds}".split(', ')
embeddeds.each {
embeddedLibrary "${it}"
}
}
if (project.hasProperty('curseforge_tools')) {
final def tools = "${project.curseforge_tools}".split(', ')
tools.each {
tool "${it}"
}
}
if (project.hasProperty('curseforge_incompatibles')) {
final def incompatibles = "${project.curseforge_incompatibles}".split(', ')
incompatibles.each {
incompatible "${it}"
}
}
if (project.hasProperty('curseforge_includes')) {
final def includes = "${project.curseforge_includes}".split(', ')
includes.each {
include "${it}"
}
}
}
}
}
if (getBooleanProperty('create_api_jar')) {
addArtifact(apiJar) {
if (getBooleanProperty('curseforge_use_custom_display_name')) {
displayName = "${project.name} ${project.display_version} API"
}
}
}
if (getBooleanProperty('create_source_jar')) {
addArtifact(sourceJar) {
if (getBooleanProperty('curseforge_use_custom_display_name')) {
displayName = "${project.name} ${project.display_version} Sources"
}
}
}
if (getBooleanProperty('create_deobf_jar')) {
addArtifact(deobfJar) {
if (getBooleanProperty('curseforge_use_custom_display_name')) {
displayName = "${project.name} ${project.display_version} Development"
}
}
}
if (getBooleanProperty('create_javadoc_jar')) {
addArtifact(javadocJar) {
if (getBooleanProperty('curseforge_use_custom_display_name')) {
displayName = "${project.name} ${project.display_version} Javadoc"
}
}
}
}
}
}
sonarqube {
properties {
if (project.hasProperty('sonar_host_url')) {
property 'sonar.host.url', project.sonar_host_url
} else if (secret.sonarHost != '') {
property 'sonar.host.url', secret.sonarHost
}
property 'sonar.login', secret.sonarToken
if (project.hasProperty('sonar_organisation')) {
property 'sonar.organization', project.sonar_organisation
} else if (secret.sonarOrganisation != '') {
property 'sonar.organization', secret.sonarOrganization
}
//property 'sonar.projectName', project.archivesBaseName
//property 'sonar.projectKey', "${project.group}:${project.archivesBaseName}"
//property 'sonar.branch.name', 'master-1.12.2'
//property 'sonar.branch.target', ''
property 'sonar.junit.reportPaths', "${project.buildDir}/test-results/junit-platform/*.xml"
property 'sonar.jacoco.reportPaths', "${project.buildDir}/jacoco/junitPlatformTest.exec"
}
}
String getModFile() {
String path = ''
final FileTree tree = fileTree(dir: 'src/main/java')
tree.include '**/*.java'
tree.visit { final element ->
if (element.file.isFile()) {
element.file.eachLine { final String s ->
final String sTrim = s.trim()
if (sTrim.startsWith('@Mod(')) {
path = "src/main/java/${element.relativePath}"
}
}
}
}
return path
}
String getModVersion(final String type) {
return getModVersion(type, modFile)
}
import java.util.regex.Matcher
String getModVersion(final String type, final String modFile) {
if ((modFile != null) && (modFile != '')) {
final File file = file(modFile)
final def prefix = ~/^(?:\s*)(?:(?<modifier>public|protected|private) )?(?:(?<static>static) )?(?:(?<final>final) )?String $type = "(?:(?<major>\d*)\.)?(?:(?<minor>\d*)\.)?(?:(?<patch>[^."]*)\.?)(?<build>[^"]*)";$/
for (final String s in file.readLines()) {
final Matcher matcher = (s.trim() =~ prefix)
if (matcher.matches()) {
return "${matcher.group('major') ?: '0'}.${matcher.group('minor') ?: '0'}.${matcher.group('patch')}"
}
}
}
return '0.0.0'
}
boolean getBooleanProperty(final String property) {
if (project.hasProperty(property)) {
return ((String) project.findProperty(property)).toBoolean()
} else {
return false
}
}
Object findProperty(final String propertyName) {
return hasProperty(propertyName) ? property(propertyName) : null;
}