-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
432 lines (370 loc) · 14.7 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
// For those who want the bleeding edge
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
}
dependencies {
classpath forgegradle
}
}
plugins {
id 'com.palantir.git-version' version '0.7.1'
id 'co.riiid.gradle' version '0.4.2'
id 'com.jfrog.bintray' version '1.7.3'
id 'com.matthewprenger.cursegradle' version '1.0.8'
}
project.metaClass {
isProperty = { propName ->
return delegate.hasProperty(propName) && !delegate.property(propName).empty
}
}
apply plugin: forgegradle_plugin
apply plugin: 'maven-publish'
import org.apache.commons.lang.StringUtils
ext {
mod_build_prefix = 'b'
assert project.isProperty('version_major'): 'missing property: version_major'
assert project.isProperty('version_minor'): 'missing property: version_minor'
assert project.isProperty('version_patch'): 'missing property: version_patch'
mod_travis = System.getenv('TRAVIS') as boolean
mod_buildnumber = System.getenv('TRAVIS_BUILD_NUMBER') as Integer
mod_buildtag = System.getenv('TRAVIS_TAG')
mod_prerelease = mod_autorelease = mod_travis && StringUtils.isEmpty(mod_buildtag)
if (mod_buildtag != null && mod_buildtag.startsWith(mod_build_prefix))
throw new GradleException("Oops, circulated travis build. A push starting with the prefix '${mod_build_prefix}' was detected: ${mod_buildtag}")
mod_version_min = "${project.version_major}.${project.version_minor}.${project.version_patch}"
mod_version = mod_buildnumber != null ? "${mod_version_min}.${mod_buildnumber}" : "${mod_version_min}"
mod_artifacts_dir = file "artifacts/${mod_version_min}/${mod_version}"
mod_artifacts_release_dir = file 'artifacts/release'
mod_git_repo = plugins.findPlugin('com.palantir.git-version').gitRepo(rootProject).repository
mod_git_head = mod_git_repo.getRef('HEAD').objectId.name()
def parseChangelog = { changelog ->
def title = null
def msg = null
def releasetype = 'release'
if (changelog != null) {
if (StringUtils.contains(changelog, '[beta]')) {
changelog = StringUtils.replace(changelog, '[beta]', '')
releasetype = 'beta'
} else if (StringUtils.contains(changelog, '[alpha]')) {
changelog = StringUtils.replace(changelog, '[alpha]', '')
releasetype = 'alpha'
}
def tagtitle = StringUtils.substringBefore(changelog, '\n')
def tagmsg = StringUtils.stripStart(StringUtils.substringAfter(changelog, '\n'), '\n')
if (!StringUtils.isEmpty(tagtitle) && !StringUtils.isEmpty(tagmsg)) {
title = tagtitle
msg = tagmsg
}
}
return [title, msg, releasetype]
}
(mod_changelog_title, mod_changelog, mod_releasetype) = ({
def (changelog_title, changelog, releasetype) = parseChangelog(({
if (!StringUtils.isEmpty(mod_buildtag)) {
def git_ref = mod_git_repo.getRef "refs/tags/${mod_buildtag}"
if (git_ref != null) {
def git_revwalk = new org.eclipse.jgit.revwalk.RevWalk(mod_git_repo)
try {
return git_revwalk.parseTag(git_ref.getObjectId()).getFullMessage()
} catch (org.eclipse.jgit.errors.IncorrectObjectTypeException e) {
} finally {
git_revwalk.dispose()
}
}
}
return null
})())
def (r_changelog_title, r_changelog) = ({
def r_change = [changelog_title, changelog]
*.replace('{version}', mod_version)
if (mod_buildnumber == null)
return r_change
else if (mod_buildnumber != null)
return r_change
*.replace('{version_number}', mod_buildnumber)
})()
if (mod_buildnumber != null) {
if (changelog_title != null && changelog != null)
return [r_changelog_title, r_changelog, releasetype]
return ["v${mod_version}", "v${mod_version_min} Build${mod_buildnumber}", 'alpha']
} else {
if (changelog_title != null && changelog != null)
return [r_changelog_title, r_changelog, releasetype]
return ["v${mod_version}", "v${mod_version}", 'alpha']
}
})()
mod_deploy_target = file 'deploy.txt'
sec_curseforge_key = System.getenv('CURSEFORGE_TOKEN') ?: project.isProperty('api_key_curseforge') ? project.api_key_curseforge : null
sec_github_key = System.getenv('GITHUB_TOKEN') ?: project.isProperty('api_key_github') ? project.api_key_github : null
sec_bintray_user = System.getenv('BINTRAY_USER') ?: project.isProperty('api_user_bintray') ? project.api_user_bintray : null
sec_bintray_key = System.getenv('BINTRAY_KEY') ?: project.isProperty('api_key_bintray') ? project.api_key_github : null
sec_keystore_location = System.getenv('KEYSTORE_LOCATION') ?: project.isProperty('keystore_location') ? project.keystore_location : null
sec_keystore_alias = System.getenv('KEYSTORE_ALIAS') ?: project.isProperty('keystore_alias') ? project.keystore_alias : null
sec_keystore_password = System.getenv('KEYSTORE_PASSWORD') ?: project.isProperty('keystore_password') ? project.keystore_password : null
commonManifest = {
if (project.isProperty('extra_fmlcore'))
attributes 'FMLCorePlugin': project.extra_fmlcore
if (project.isProperty('extra_fmlmod'))
attributes 'FMLCorePluginContainsFMLMod': project.extra_fmlcore
if (project.isProperty('extra_fmlat'))
attributes 'FMLAT': project.extra_fmlat
}
}
tasks.withType(Jar) {
compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
task setupSourceSets {
doLast {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
[tasks.eclipseClasspath, tasks.ideaModule]*.dependsOn 'setupSourceSets'
}
sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = "1.8"
}
version = "${version_minecraft}-${mod_version}"
minecraft {
version = "${project.version_minecraft}-${project.version_forge}"
if (project.isProperty('version_mappings'))
mappings = project.version_mappings
if (!project.isProperty('run_location'))
runDir = 'run'
else
runDir = run_location.replace('{modid}', project.modid).replace('{mcversion}', project.version_minecraft)
replaceIn 'Reference.java'
replace '{modid}', project.modid
replace '{modname}', project.modname
replace '{version}', mod_version
replace '{mcversion}', project.version_minecraft
replace '{forgeversion}', project.version_forge
}
repositories {
mavenCentral()
jcenter()
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
}
dependencies {
}
processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand([
'modid' : project.modid,
'modname' : project.modname,
'version' : mod_version,
'mcversion' : project.version_minecraft,
'forgeversion' : project.version_forge,
'minforgeversion': project.isProperty('version_minforge') ? project.version_minforge : project.version_forge,
])
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
// An Error occured while switching above 1.8 -> under 1.7
task cleanMakeStart(type: Delete) {
// makeStart.dependsOn 'cleanMakeStart'
delete file(new File(tasks.makeStart.getTemporaryDir(), 'extracted'))
}
jar {
from sourceSets.main.output
from sourceSets.api.output
manifest commonManifest
}
if (tasks.findByPath('sourceJar')==null) {
task sourceJar(dependsOn: 'classes', type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
manifest commonManifest
}
}
sourceJar {
from sourceSets.api.allSource
}
task devJar(dependsOn: 'classes', type: Jar) {
from sourceSets.main.output
from sourceSets.api.output
classifier 'dev'
manifest commonManifest
}
task apiJar(dependsOn: 'classes', type: Jar) {
from sourceSets.api.output
classifier 'api'
manifest commonManifest
}
[jar, devJar, sourceJar, apiJar]*.destinationDir = mod_artifacts_dir
artifacts {
archives jar
archives devJar
archives sourceJar
archives apiJar
}
task signJars(dependsOn: 'build') {
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(tasks.signJars))
assert sec_keystore_location != null, 'missing sec_keystore_location'
}
def keystore_location = sec_keystore_location ?: ''
def keystore_alias = sec_keystore_alias ?: ''
def keystore_password = sec_keystore_password ?: ''
inputs.dir jar.destinationDir
inputs.file keystore_location
inputs.property 'keystore_alias', keystore_alias
inputs.property 'keystore_password', keystore_password
outputs.dir jar.destinationDir
doLast {
[jar, devJar, sourceJar, apiJar].each { eachtask ->
eachtask.outputs.files.each { file ->
if (!file.path.endsWith('.jar'))
return
logger.lifecycle "signing ${file}"
ant.signjar(
destDir: file.parentFile,
jar: file,
keystore: keystore_location,
alias: keystore_alias,
storepass: keystore_password
)
}
}
}
}
task deploy(dependsOn: 'build', type: Copy) {
mustRunAfter 'signJars'
if (mod_deploy_target.exists())
mod_deploy_target.eachLine { target ->
def dest = target.endsWith('.jar') ? target.parentFile : target
from(project.tasks.jar.outputs.files.singleFile)
into(dest)
rename { String oldname ->
target.endsWith('.jar') ? target.name : oldname
}
eachFile { file ->
def path = file.relativePath.getFile(dest)
logger.lifecycle "copying to ${path}"
}
}
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(tasks.curseforge)) {
assert sec_curseforge_key != null, 'missing sec_curseforge_key'
assert project.isProperty('extra_curseforge_id'), 'missing extra_curseforge_id'
}
}
if (sec_curseforge_key != null && project.isProperty('extra_curseforge_id')) {
curseforge {
tasks.curseforge.enabled = !mod_autorelease
tasks.curseforge.dependsOn 'reobfShadowJar'
tasks.curseforge.mustRunAfter 'signJars'
apiKey = sec_curseforge_key
project {
id = project.extra_curseforge_id
changelogType = 'markdown'
changelog = mod_changelog
releaseType = mod_releasetype
mainArtifact(jar) {
displayName = "${jar.baseName}-${jar.version}"
}
[devJar, sourceJar, apiJar].each { jar ->
addArtifact(jar) {
displayName = "${jar.baseName}-${jar.version}-${jar.classifier}"
}
}
relations {
}
}
}
} else
tasks.curseforge.enabled = false
task releaseArtifacts(dependsOn: 'build', type: Sync) {
from mod_artifacts_dir
into mod_artifacts_release_dir
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(tasks.githubRelease)) {
assert sec_github_key != null, 'missing sec_github_key'
assert project.isProperty('extra_github_owner'), 'missing extra_github_owner'
assert project.isProperty('extra_github_repo'), 'missing extra_github_repo'
}
}
if (sec_github_key != null && project.isProperty('extra_github_owner') && project.isProperty('extra_github_repo')) {
github {
tasks.githubRelease.dependsOn 'build'
prerelease = mod_prerelease
owner = project.extra_github_owner
repo = project.extra_github_repo
token = sec_github_key
tagName = mod_travis ? (mod_autorelease ? "${mod_build_prefix}${mod_buildnumber}" : mod_buildtag) : mod_version
targetCommitish = mod_git_head
name = mod_changelog_title
body = mod_changelog
draft = false
assets = [jar, devJar, sourceJar, apiJar]*.outputs*.files*.asPath*.tr('\\', '/')
}
}
publishing {
publications {
ModPublication(MavenPublication) {
groupId = project.group
artifactId = project.modid
version = "${mod_version}"
artifact jar
artifact jar
artifact devJar
artifact sourceJar
artifact apiJar
}
}
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(tasks.bintrayUpload)) {
assert sec_bintray_user != null, 'missing sec_bintray_user'
assert sec_bintray_key != null, 'missing sec_bintray_key'
assert project.isProperty('extra_bintray_repo'), 'missing extra_bintray_repo'
assert project.isProperty('extra_bintray_name'), 'missing extra_bintray_name'
}
}
if (sec_bintray_user != null && sec_bintray_key != null && project.isProperty('extra_bintray_repo') && project.isProperty('extra_bintray_name')) {
bintray {
tasks.bintrayUpload.enabled = !mod_autorelease
user = sec_bintray_user
key = sec_bintray_key
publications = ['ModPublication']
publish = true
pkg {
repo = project.extra_bintray_repo
name = project.extra_bintray_name
version {
name = "${mod_version}"
released = new Date()
}
}
}
} else
tasks.bintrayUpload.enabled = false