forked from JackyyTV/DimensionalEdibles
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
302 lines (255 loc) · 8.37 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
import java.util.regex.Pattern
import groovy.json.JsonSlurper
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
buildscript {
repositories {
mavenCentral()
maven {
name = "Forge"
url = "https://maven.minecraftforge.net/"
}
maven {
name = "jitpack"
url = "https://jitpack.io"
}
}
dependencies {
classpath "com.github.GregTechCE:ForgeGradle:FG_2.3-SNAPSHOT"
classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
classpath "org.apache.httpcomponents:httpmime:4.5.1"
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
group = "jackyy.dimensionaledibles"
version = getRewrittenVersion()
archivesBaseName = "DimensionalEdibles"
sourceCompatibility = targetCompatibility = "1.8"
compileJava {
sourceCompatibility = targetCompatibility = "1.8"
}
minecraft {
version = "${forge_version}"
runDir = "run"
mappings = "${mappings_version}"
replace "GRADLE:VERSION", project.version
replace '@FINGERPRINT@', project.findProperty('signSHA1')
replaceIn "DimensionalEdibles.java"
}
repositories {
maven {
name = "JEI Maven"
url "https://dvs1.progwml6.com/files/maven"
}
maven {
name = "Hwyla Maven"
url "http://maven.tehnut.info"
}
maven {
name = "TOP Maven"
url = "http://maven.tterrag.com"
}
maven {
name = "FTBLib"
url "https://maven.latmod.com/"
}
}
dependencies {
deobfCompile "mezz.jei:jei_1.12.2:+"
deobfCompile "mcp.mobius.waila:Hwyla:1.8.26-B41_1.12.2"
deobfCompile "mcjty.theoneprobe:TheOneProbe-1.12:1.12-1.4.+"
deobfCompile "com.feed_the_beast.mods:FTBLib:5.+"
testImplementation "junit:junit:4.13.1"
testImplementation "org.hamcrest:hamcrest:2.2"
}
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
task signJar(type: SignJar, dependsOn: reobfJar) {
onlyIf {
project.hasProperty('keyStore')
}
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = jar.archivePath
outputFile = jar.archivePath
}
build.dependsOn signJar
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
}
artifacts {
archives deobfJar
}
/*
Fetches the last tag associated with the current branch.
*/
def getLastTag() {
return run("git describe --abbrev=0 --tags " +
(System.env["TRAVIS_TAG"] ? run("git rev-list --tags --skip=1 --max-count=1") : "")
)
}
/*
Runs a command and returns the output.
*/
def run(command) {
def process = command.execute()
def outputStream = new StringBuffer();
def errorStream = new StringBuffer();
process.waitForProcessOutput(outputStream, errorStream)
errorStream.toString().with {
if (it) {
throw new GradleException("Error executing ${command}:\n> ${it}")
}
}
return outputStream.toString().trim()
}
/*
Rewrites the version.
*/
def getRewrittenVersion () {
def lastTag = getLastTag()
if (System.env['TRAVIS_TAG']) {
return System.env['TRAVIS_TAG'] + ".0"
} else {
def commitNo = run "git rev-list ${lastTag}..HEAD --count"
return lastTag + "." + commitNo
}
}
task generateChangelog {
onlyIf {
System.env['TRAVIS']
}
doLast {
/*
Create a comprehensive changelog.
*/
def lastTag = getLastTag()
def changelog = (run([
"git"
, "log"
, "--date=format:%d %b %Y"
, "--pretty=%s - **%an** (%ad)"
, "${lastTag}..HEAD"
].plus(
/*
Collect relevant directories only, them being:
* ./src/main/java
* ./src/main/resources
*/
sourceSets.main.java.srcDirs
.plus(sourceSets.main.resources.srcDirs)
.collect { [ "--", it ] }
).flatten()))
if (changelog) {
changelog = "Changes since ${lastTag}:\n${("\n" + changelog).replaceAll("\n", "\n* ")}"
}
def f = new File("build/tmp/changelog.md")
f.write(changelog ?: "", "UTF-8")
}
}
compileJava.dependsOn generateChangelog
task deployCurseForge {
doLast {
def final CURSEFORGE_ENDPOINT = "https://minecraft.curseforge.com/"
/*
Helper function for checking environmental variables.
*/
def final checkVariables = { variables ->
for (vari in variables) {
if (!System.env[vari]) {
throw new GradleException("Environmental variable ${vari} is unset")
}
}
}
checkVariables([
'CURSEFORGE_API_TOKEN', 'CURSEFORGE_PROJECT_ID'
])
/*
Helper function for fetching JSON data.
*/
def final fetch = { url, headers = null ->
def connection = new URL(url).openConnection();
connection.setRequestProperty("X-Api-Token", System.env["CURSEFORGE_API_TOKEN"])
if (headers != null) {
for (header in headers) {
connection.setRequestProperty(headers[1], headers[2])
}
}
def code = connection.getResponseCode()
if (code == 200) {
return new JsonSlurper().parseText(connection.getInputStream().getText())
} else {
throw new GradleException("Fetch failed with code ${code} (${url})")
}
}
/*
Fetch the list of Minecraft versions from CurseForge.
*/
def targetVersion = project.minecraft.version
def version = fetch(CURSEFORGE_ENDPOINT + "api/game/versions").with {
def v = it.find { it.name == targetVersion }
if (!v) {
throw new GradleException("Version ${project.minecraft.version} not found on CurseForge")
}
return v
}
/*
Fill the papers for CurseForge.
*/
def metadata = new groovy.json.JsonBuilder().with {
def versions = [ version.id ]
/*
CurseForge is dumb, so we'll have to prepend two spaces
to each newline. This is disgusting, but it works.
*/
def log = new File("build/tmp/changelog.md")
.getText("UTF-8")
.replaceAll("\n", " \n")
.replaceAll("\n\\*", "\n•")
def root = it {
changelog log
changelogType "markdown"
releaseType System.env['TRAVIS_TAG'] ? "release" : "beta"
gameVersions versions
// Defined in gradle.properties
displayName "${project_fancy_name} ${project.version}"
}
if (project_curseforge_dependencies) {
def data = new JsonSlurper().parseText(project_curseforge_dependencies)
root << [relations: [ projects: data ]]
}
return it.toString()
}
/*
Upload the artifact to CurseForge.
*/
new HTTPBuilder(CURSEFORGE_ENDPOINT).request(Method.POST) { req ->
requestContentType = "multipart/form-data"
headers["X-Api-Token"] = System.env["CURSEFORGE_API_TOKEN"]
uri.path = "api/projects/${System.env["CURSEFORGE_PROJECT_ID"]}/upload-file"
req.entity = new MultipartEntityBuilder().with {
addPart("file", new FileBody(
new File("${project.jar.destinationDir}/${project.jar.archiveName}")
))
addPart("metadata", new StringBody(metadata))
return it.build()
}
}
}
}