forked from Team-Fruit/Emojicord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
260 lines (233 loc) · 8.18 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
// Buildscript Dependencies
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
// for ForgeGradle Version
classpath 'com.google.guava:guava:26.0-jre'
// for CurseGradle
classpath 'org.apache.httpcomponents:httpmime:4.5.2'
classpath 'org.apache.httpcomponents:httpclient:4.5.2'
}
}
// 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'
}
// 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_build_prefix = 'build/b'
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_git_repo = plugins.findPlugin('com.palantir.git-version').gitRepo(rootProject).repository
mod_git_head = mod_git_repo.getRef('HEAD').objectId.name()
mod_version_min = ({
def git_ref = mod_git_repo.getRef "refs/remotes/origin/update"
if (git_ref != null) {
def git_revwalk = new org.eclipse.jgit.revwalk.RevWalk(mod_git_repo)
try {
return git_revwalk.parseCommit(git_ref.getObjectId()).getShortMessage()
} catch (org.eclipse.jgit.errors.IncorrectObjectTypeException e) {
} finally {
git_revwalk.dispose()
}
}
return null
})()
if (mod_version_min == null) {
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_version_min = "${project.version_major}.${project.version_minor}.${project.version_patch}"
}
println("ModVersion: ${mod_version_min}")
(mod_version_build, mod_version_meta) = ({
if (mod_buildnumber)
return [".${mod_buildnumber}", '']
else
return [".git", '']
})()
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}"
// 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]
})()
}
// Configure Tokens
ext {
sec_curseforge_key = System.getenv('CURSEFORGE_TOKEN') ?: project.isProperty('api_key_curseforge') ? project.api_key_curseforge : null
sec_github_user = System.getenv('GITHUB_ACTOR') ?: project.isProperty('api_user_github') ? project.api_user_github : null
sec_github_key = System.getenv('GH_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
project(':versions').subprojects {
rootProject.evaluationDependsOn(project.path)
}
// Plugins
apply plugin: 'maven-publish'
// Configure Version
version = "${mod_version}"
// Release GitHub
if (sec_github_key!=null&&project.isProperty('extra_github_owner')&&project.isProperty('extra_github_repo')) {
//tasks.githubRelease.enabled = !mod_autorelease
github {
project(':versions').subprojects.each { tasks.githubRelease.dependsOn(it.tasks.findByName('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
List<Task> allassets = []
project(':versions').subprojects {
allassets.addAll([tasks.shadowJar, tasks.jar, tasks.devJar, tasks.sourceJar, tasks.apiJar])
}
assets = allassets*.outputs*.files*.asPath*.tr('\\','/')
}
} else
tasks.githubRelease.enabled = false
// Maven Publishing
publishing {
publications {
project(':versions').subprojects {
"ModPublication-${project.version_minecraft}"(MavenPublication) {
groupId = project.group
artifactId = project.modid
version = "${project.version_minecraft}-${project.mod_version}"
artifact project.shadowJar
//artifact project.jar
artifact project.devJar
artifact project.sourceJar
artifact project.apiJar
}
}
}
if (!mod_autorelease) {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${project.extra_github_owner}/${project.extra_github_repo}")
credentials {
username = sec_github_user
password = sec_github_key
}
}
}
}
}
// Release Bintray
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
project(':versions').subprojects.each { tasks.githubRelease.dependsOn(it.tasks.findByName('build')) }
user = sec_bintray_user
key = sec_bintray_key
def pubs = ['ModPublication']
project(':versions').subprojects {
pubs += "ModPublication-${project.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