forked from SilentChaos512/ScalingHealth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
419 lines (359 loc) · 11.5 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
buildscript {
repositories {
jcenter()
maven {
name = 'forge'
url = 'http://files.minecraftforge.net/maven'
}
maven {
name = 'gradle'
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath "net.minecraftforge.gradle:${project.fg_version}"
}
}
plugins {
id 'maven'
id 'maven-publish'
id "com.jfrog.bintray" version "1.8.1"
id "com.matthewprenger.cursegradle" version "1.2.0"
id 'net.ltgt.apt' version '0.10' // for lombok
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.matthewprenger.cursegradle'
repositories {
flatDir {
name "fileRepo"
dirs "repo"
}
mavenLocal()
mavenCentral()
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs = [
'-Xlint:deprecation', // deprecation, rawtypes, cast, unchecked, all
// '-Xdiags:verbose',
// '-Werror'
]
}
javadoc {
failOnError = false
}
def versionInfo = getModVersion()
System.out.println(versionInfo)
version = "${versionInfo['version']}"
def build_num = getBuildNumber()
sourceCompatibility = targetCompatibility = '1.8'
eclipse.project {
buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
natures 'org.eclipse.buildship.core.gradleprojectnature'
}
minecraft {
version = project.forge_mc_version + '-' + project.forge_version
runDir = 'run'
mappings = project.mcp_mappings
replace "BUILD_NUM = 0", "BUILD_NUM = " + build_num
replaceIn "${project.archivesBaseName}.java"
if (project.hasProperty('coreplugin')) {
clientJvmArgs += '-Dfml.coreMods.load=' + project.coreplugin
serverJvmArgs += '-Dfml.coreMods.load=' + project.coreplugin
}
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]
}
// disable server gui
serverRunArgs += 'nogui'
// skip the screen to confirm that you want to load a world with missing registry entries
serverJvmArgs += '-Dfml.doNotBackup=true'
clientJvmArgs += '-Dfml.doNotBackup=true'
// skip having to confirm on server
serverJvmArgs += '-Dfml.queryResult=confirm'
//skip jansi warnings in the log
serverJvmArgs += '-Dlog4j.skipJansi=true'
clientJvmArgs += '-Dlog4j.skipJansi=true'
if (project.hasProperty('client_args')) {
clientJvmArgs += project.client_args
}
if (project.hasProperty('server_args')) {
serverJvmArgs += project.server_args
}
}
repositories {
jcenter()
mavenCentral()
maven { // JEI
name = "Progwml6 maven"
url = "http://dvs1.progwml6.com/files/maven"
}
maven { // JEI mirror
name = "ModMaven"
url = "modmaven.k-4u.nl"
}
maven {
name "Cyclops Repo"
url "https://oss.jfrog.org/artifactory/simple/libs-release/"
}
repositories {
maven { url 'https://maven.mcmoddev.com' }
}
}
dependencies {
// lombok
compile "org.projectlombok:lombok:${project.lombok_version}"
apt "org.projectlombok:lombok:${project.lombok_version}"
// JEI
deobfProvided "mezz.jei:jei_${project.mc_version}:${project.jei_version}:api"
runtime "mezz.jei:jei_${project.mc_version}:${project.jei_version}"
// Silent Lib
compile "net.silentchaos512:silent-lib:3.0+"
// Game Stages
compile "net.darkhax.gamestages:GameStages-${project.mc_version}:${project.gamestages_version}"
runtime "net.darkhax.bookshelf:Bookshelf-1.12.2:2.3.552"
}
processResources {
inputs.property 'version', project.version
inputs.property 'mcversion', project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version': "${versionInfo['version_short']}", 'mcversion': project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
rename '(.+_at.cfg)', 'META-INF/$1'
}
jar {
appendix = "${project.mc_version}"
}
task apiJar(type: Jar) {
appendix = "${project.mc_version}"
classifier = 'apiClasses'
from apiClasses
}
task deobfJar(type: Jar) {
appendix = "${project.mc_version}"
classifier = 'deobf'
from sourceSets.main.output
}
task sourcesJar(type: Jar) {
appendix = "${project.mc_version}"
classifier = 'sources'
from sourceSets.main.allJava
}
task javadocJar(type: Jar, dependsOn: javadoc) {
appendix = "${project.mc_version}"
classifier = 'javadoc'
from javadoc.getDestinationDir()
}
artifacts {
if (project.hasProperty('doAPIJar')) {
archives apiJar
}
if (project.hasProperty('doDeobfJar')) {
archives deobfJar
}
if (project.hasProperty('doSourceJar')) {
archives sourceJar
}
if (project.hasProperty('doJavadocJar')) {
archives javadocJar
}
}
class Secrets {
def data = null
def getProperty(String key) {
return data ? data[key] : ''
}
}
import groovy.json.JsonSlurper
def secretFile
if (System.getenv().SECRET_FILE) {
secretFile = file System.getenv().SECRET_FILE
} else {
secretFile = file 'secret.json'
}
project.ext.secret = new Secrets()
if (secretFile.exists()) {
secretFile.withReader {
project.ext.secret.data = new JsonSlurper().parse it
}
}
curseforge {
if (project.hasProperty('cf_project_id') && project.hasProperty('cf_release_type') && project.hasProperty('cf_changelog_filename') &&
((project.cf_release_type == 'alpha') || (project.cf_release_type == 'beta') || (project.cf_release_type == 'release'))) {
apiKey = secret.curseforgeAPIKey
project {
id = project.cf_project_id
changelog = file(project.cf_changelog_filename)
releaseType = project.cf_release_type
addGameVersion(project.mc_version)
mainArtifact(jar) {
// displayName = "$project.description $display_version"
relations {
requiredDependency 'silent-lib'
}
}
// if (project.hasProperty('doAPIJar')) {
// addArtifact(apiJar) {
// displayName = "$project.description $display_version API"
// }
// }
// if (project.hasProperty('doSourceJar')) {
// addArtifact(sourceJar) {
// displayName = "$project.description $display_version Sources"
// }
// }
// if (project.hasProperty('doDeobfJar')) {
// addArtifact(deobfJar) {
// displayName = "$project.description $display_version Development"
// }
// }
// if (project.hasProperty('doJavadocJar')) {
// addArtifact(javadocJar) {
// displayName = "$project.description $display_version Javadoc"
// }
// }
}
}
}
// Bintray/Maven publishing
publishing {
publications {
scalingHealth(MavenPublication) {
groupId 'net.silentchaos512'
artifactId 'scaling-health'
version "${versionInfo['version_short']}".toString()
from components.java
artifact sourcesJar
artifact javadocJar
}
}
}
bintray {
// Not sure if this syntax works, need to test
user = secret.BINTRAY_USER ?: System.getenv('BINTRAY_USER')
key = secret.BINTRAY_KEY ?: System.getenv('BINTRAY_KEY')
publications = ['scalingHealth']
pkg {
repo = 'scaling-health'
name = 'scaling-health'
licenses = ["LGPL-3.0"]
vcsUrl = 'https://github.com/SilentChaos512/ScalingHealth.git'
version {
name = "${versionInfo['version_short']}".toString()
desc = "Scaling Health (1.12.2) ${versionInfo['version_short']}".toString()
released = new Date()
vcsTag = "v${versionInfo['version_short']}".toString()
}
}
}
// Version stuff
def getModVersion() {
try {
return getGitVersion()
} catch (Exception ex) {
System.out.println("Git version failed, falling back to old method")
return getVersion('VERSION', getModFile())
}
}
def getGitVersion() {
// Call git command
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = [ 'describe', '--long' ]
standardOutput = outStream
}
def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+).(\d+)-(.*)/
def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = getBuildNumber()
return makeVersionMap(maj, min, rev, bn, matcher[0][4])
}
static def makeVersionMap(maj, min, rev, bn, githash) {
def out = [:]
out['build.major.number'] = maj.toString()
out['build.minor.number'] = min.toString()
out['build.revision.number'] = rev.toString()
out['build.githash'] = githash
out['build.number'] = bn.toString()
out['version_short'] = "${maj}.${min}.${rev}".toString()
out['version'] = "${maj}.${min}.${rev}+${bn}".toString()
return out
}
// Modified old version getter
def getVersion(String type, String mod_file) {
String maj = '0'
String min = '0'
String rev = '0'
String bn = getBuildNumber()
File file = file(mod_file)
def prefix = ~/^(?:public|protected|private) static final String $type = ".*$/
file.eachLine { String s ->
s = s.trim()
if (s ==~ prefix || prefix.matcher(s).matches()) {
String[] bits = s.split("=")
String interesting = bits[1].trim()
interesting = interesting.substring(1, interesting.length() - 2)
String[] pts = interesting.trim().split("\\.")
maj = pts[0] ?: '0'
min = pts[1] ?: '0'
rev = pts[2] ?: '0'
}
}
return makeVersionMap(maj, min, rev, bn, 'unknown')
}
// Used by old getVersion
String getModFile() {
String path = ''
FileTree tree = fileTree(dir: 'src/main/java')
tree.include '**/*.java'
tree.visit { element ->
if (element.file.isFile()) {
element.file.eachLine { String s ->
s = s.trim()
if (s.startsWith('@Mod(')) {
path = "src/main/java/$element.relativePath"
}
}
}
}
return path
}
// Build number tracking
String getBuildNumber() {
def versionFile = file('version.properties')
if (versionFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
return versionProps['build_num'].toString()
}
return "1"
}
task incrementBuild {
doFirst {
def versionFile = file('version.properties')
if (versionFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
def num = versionProps['build_num'].toInteger() + 1
println("incrementing BuildNumber to: " + num)
versionProps['build_num'] = num.toString()
versionProps.store(versionFile.newWriter(), null)
} else {
println("version.properties file not found! Ignoring.")
}
}
}
build.finalizedBy incrementBuild // only increment on successful builds