-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
360 lines (317 loc) · 10.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
// Buildscript Dependencies
buildscript {
}
// Plugins
plugins {
id 'com.palantir.git-version' version '0.7.1'
id 'co.riiid.gradle' version '0.4.2'
id 'com.jfrog.bintray' version '1.8.4'
id 'com.matthewprenger.cursegradle' version '1.0.10'
}
// Configure Utility
allprojects {
project.metaClass {
isProperty = { propName ->
return delegate.hasProperty(propName)&&!delegate.property(propName).empty
}
}
}
// Configure Variables
import org.apache.commons.lang.StringUtils
ext {
mod_commonname = "${rootProject.name}-common"
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_build, mod_version_meta) = ({
if (mod_buildnumber)
return [".${mod_buildnumber}", '']
else
return ({
def buildnumberfile = file '.buildnumber/buildnum.properties'
def version_build = ({
def buildnumbermicro = 1
def props = new Properties()
if (buildnumberfile.exists())
buildnumberfile.withInputStream { stream ->
props.load stream
}
if (props.buildnumber &&
props.version_major == project.version_major &&
props.version_minor == project.version_minor &&
props.version_patch == project.version_patch)
buildnumbermicro = props.buildnumber as Integer
return buildnumbermicro
})()
def buildtextmicro = String.format('%03d', version_build)
def buildtext = "+${buildtextmicro}"
task increment {
doLast {
def props = new Properties()
props.version_major = project.version_major
props.version_minor = project.version_minor
props.version_patch = project.version_patch
props.buildnumber = version_build+1 as String
buildnumberfile.parentFile.mkdirs()
buildnumberfile.withOutputStream { stream ->
props.store stream, 'Build Number Property'
}
}
}
subprojects {
afterEvaluate {
tasks.build.dependsOn increment
}
}
['', buildtext]
})()
})()
mod_version_min = "${project.version_major}.${project.version_minor}.${project.version_patch}"
mod_version = "${mod_version_min}${mod_version_build}"
mod_version_full = "${mod_version}${mod_version_meta}"
mod_artifacts_dir = file "artifacts/${mod_version_min}/${mod_version_full}"
mod_git_repo = plugins.findPlugin('com.palantir.git-version').gitRepo(rootProject).repository
mod_git_head = mod_git_repo.getRef('HEAD').objectId.name()
// Parse Changelog
def parseChangelog = { changelog ->
def title = null
def msg = null
def releasetype = 'release'
if (changelog!=null) {
// Beta mode and Alpha mode
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'
}
// Split Title and Body
def tagtitle = StringUtils.substringBefore(changelog, '\n')
def tagmsg = StringUtils.stripStart(StringUtils.substringAfter(changelog, '\n'), '\n')
if (!StringUtils.isEmpty(tagtitle))
title = tagtitle
if (!StringUtils.isEmpty(tagmsg))
msg = tagmsg
}
return [title, msg, releasetype]
}
// Changelog Text
(mod_changelog_title, mod_changelog, mod_releasetype) = ({
// Get Changelog from Git Tag or File
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()
}
}
} else {
def fileChangelog = project.isProperty('extra_changelog_location') ? file(project.extra_changelog_location) : file('changelog.md')
if (fileChangelog.exists())
return fileChangelog.getText('UTF-8')
}
return null
})())
// Replace Version Text
def convertChangelog = { str ->
def str1 = str
.replace('{version}', mod_version)
.replace('{version_full}', mod_version_full)
if (mod_buildnumber!=null)
return str1
.replace('{version_number}', "${mod_buildnumber}")
return str1
}
// Generate Default Changelog
def (n_changelog_title, n_changelog) = ({
if (mod_buildnumber!=null)
return ["v${mod_version}", "v${mod_version_min} Build${mod_buildnumber}"]
else
return ["v${mod_version_full}", "v${mod_version_full}"]
})()
if (changelog_title!=null)
n_changelog_title = convertChangelog(changelog_title)
if (changelog!=null)
n_changelog = convertChangelog(changelog)
return [n_changelog_title, n_changelog, releasetype]
})()
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
}
// Configure Subprojects
evaluationDependsOnChildren()
// Plugins
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven-publish'
// Configure Source Sets
sourceSets {
delegate.each { s ->
s.java {
srcDirs = []
}
s.resources {
srcDirs = []
}
}
}
// Auto-Generated Directory
task setupSourceSets {
doLast {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
[tasks.eclipseClasspath, tasks.ideaModule]*.dependsOn 'setupSourceSets'
}
// Configure Version
version = "${mod_version}"
// Universal Jar
jar {
subprojects.each { p ->
if (p.name==mod_commonname) {
manifest p.commonManifest
p.tasks.shadowJar.outputs.files.each { f ->
from zipTree(f)
}
} else {
p.tasks.jar.outputs.files.each { f ->
from(f) {
rename '.*', p.version_minecraft+'.jar'
}
}
}
dependsOn p.tasks.build
}
classifier = 'universal'
destinationDir = mod_artifacts_dir
}
// Output Jar
artifacts {
archives jar
}
// Release GitHub
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_full
targetCommitish = mod_git_head
name = mod_changelog_title
body = mod_changelog
draft = false
def allassets = [jar]
subprojects.each { p ->
allassets.addAll([p.tasks.shadowJar, p.tasks.jar, p.tasks.devJar, p.tasks.sourceJar, p.tasks.apiJar])
}
assets = allassets*.outputs*.files*.asPath*.tr('\\','/')
}
}
// Release Bintray - Maven Publishing
publishing.publications {
ModPublication(MavenPublication) {
groupId = project.group
artifactId = project.modid
version = "${mod_version}"
artifact jar
}
subprojects.each { p ->
if (p.name!=mod_commonname) {
"ModPublication-${p.version_minecraft}"(MavenPublication) {
groupId = p.group
artifactId = p.modid
version = "${p.version_minecraft}-${p.mod_version}"
artifact p.shadowJar
//artifact p.jar
artifact p.devJar
artifact p.sourceJar
artifact p.apiJar
}
}
}
}
// Release Bintray
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
def pubs = ['ModPublication']
subprojects.each { p ->
if (p.name!=mod_commonname)
pubs += "ModPublication-${p.version_minecraft}"
}
publications = pubs
publish = true
pkg {
userOrg = project.extra_bintray_org
repo = project.extra_bintray_repo
name = project.extra_bintray_name
version {
name = "${mod_version}"
released = new Date()
desc = "${mod_changelog_title}"+(StringUtils.isEmpty(mod_changelog)?'':"\n\n${mod_changelog}")
vcsTag = mod_buildtag
}
}
}
} else
tasks.bintrayUpload.enabled = false
// Release CurseForge
if (sec_curseforge_key!=null&&project.isProperty('extra_curseforge_id')) {
curseforge {
tasks.curseforge.enabled = !mod_autorelease
tasks.curseforge.dependsOn 'build'
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} Universal"
}
subprojects.each { p ->
addGameVersion p.version_minecraft
}
/*
relations {
}
*/
}
}
} else
tasks.curseforge.enabled = false