forked from TerraFirmaCraft/TerraFirmaCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
259 lines (236 loc) · 9.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
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/
/*
* !!README!!
*
* Willing contributors: Do not change anything in this file that is not marked with a comment saying you can edit it!
*
* !!README!!
*
*/
// Allow json magic in build script (used for update json file)
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
// Required build script stuff
buildscript {
repositories {
// Repositories required for ForgeGradle go here.
jcenter()
maven {
name = "forge"
url = "https://files.minecraftforge.net/maven"
}
maven {
name = "curseforge"
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
classpath "gradle.plugin.com.matthewprenger:CurseGradle:1.4.0"
classpath "com.wynprice.cursemaven:CurseMaven:2.1.0"
}
}
plugins {
id 'java'
id 'idea'
}
// Go Forge go!
apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: "com.matthewprenger.cursegradle"
apply plugin: 'com.wynprice.cursemaven'
// Load properties file, easier to manage versions of required dependencies
file "build.properties" withReader {
def prop = new Properties()
prop.load(it)
ext.config = new ConfigSlurper().parse prop
}
/**
* Version in dev is set to 'dev'
* Any builds produced by the github actions build script will have a version matching their tag.
* Versioning is highly based on semantic versioning: [MAJOR].[MINOR].[REVISION].[BUILD]
* - Major version resets on MC version changes
* - Minor version resets on added features or major changes
* - Revision resets on any bugfixes or small changes
* - Build increments, only resets on a new major version.
*/
if (System.getenv('VERSION') != null) {
version = System.getenv('VERSION')
} else {
version = 'dev'
}
group = "net.dries007.tfc" // According to java standards, as I have control over this domain. If you fork this and release your own version, change this.
archivesBaseName = "TerraFirmaCraft" // Jar filename. The final result must match ^[\w-\.]+$. (Alphanumerical + `_-.`)
sourceCompatibility = targetCompatibility = "1.8" // We require Java 8
String runGitCommand(String cmd_args)
{
// Create a new function that gets the changelog from git (used for updates json file)
try
{
def outStream = new ByteArrayOutputStream()
exec {
executable = 'git'
args(cmd_args.split(' '))
standardOutput = outStream
}
return outStream.toString().replaceAll("^\\s*'\\s*|\\s*'\\s*\$", "").replaceAll("[\\r\\n]+", "\n")
}
catch (exception)
{
logger.warn("No changelog due to error with git command line. Ignoring...", exception)
return "<ERROR>"
}
}
minecraft { // Only change any of this with prior approval from the dev team!
version = "${config.minecraft.version}-${config.forge.version}"
runDir = "run"
mappings = "stable_39"
}
repositories {
// Repositories required for dependencies, not ForgeGradle go here.
mavenCentral()
maven {
name = "CraftTweaker Maven"
url = "https://maven.blamejared.com/"
}
maven {
// location of the maven that hosts JEI files
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
}
//maven {
// name = "Hwyla maven"
// url "http://tehnut.info/maven"
//}
maven { // TOP
name 'tterrag maven'
url "https://maven.tterrag.com/"
}
maven {
name = "CoFH Maven"
url = "https://maven.covers1624.net/"
}
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
}
String mcVersion = config.minecraft.version
String shortVersion = mcVersion.substring(0, mcVersion.lastIndexOf('.'))
String strippedVersion = shortVersion.replace(".", "") + "0"
dependencies {
// Mod dependencies go here.
// Do not add dependencies without prior approval from the dev team. You can update existing ones.
deobfProvided "CraftTweaker2:CraftTweaker2-MC${strippedVersion}-Main:${config.crafttweaker.version}"
deobfProvided "mezz.jei:jei_${config.minecraft.version}:${config.jei.version}"
// For now, since maven is no show, use the curse maven plugin to resolve the exact file name
deobfProvided "curse.maven:hwyla:2568751"
//compileOnly "mcp.mobius.waila:Hwyla:${config.HWYLA.version}_${config.minecraft.version}"
deobfProvided "mcjty.theoneprobe:TheOneProbe-${shortVersion}:${config.TOP.version}"
deobfProvided "vazkii.patchouli:Patchouli:${config.patchouli.version}"
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", version
inputs.property "mcversion", config.minecraft.version
// copy mcmod.info from resources
from(sourceSets.main.resources.srcDirs) {
include "mcmod.info"
// replace version and mcversion variables/placeholders
expand "mod_version": version, "mc_version": config.minecraft.version
}
// copy everything else from resources
from(sourceSets.main.resources.srcDirs) {
exclude "mcmod.info"
}
// from the project root, include the LICENSE file
from('.') {
include "LICENSE.txt"
}
// move any Access Transformer (there is/should be only 1, but this is nice and safe) to the right folder.
rename '(.+_at.cfg)', 'META-INF/$1'
// Write the update's json file. This file is kept by jenkins and put in a WWW accessible folder.
// For more info on the exact format, see Forge documentation & source code.
doLast {
//noinspection GroovyAssignabilityCheck
def updateFile = new File('tfc.json')
def json
if (updateFile.exists()) {
json = new JsonSlurper().parseText(updateFile.getText())
} else {
def builder = new JsonBuilder()
json = builder(homepage: "https://tng.terrafirmacraft.com", promos: new HashMap<>()) // defaults: Again, change if you fork & release
}
//noinspection GroovyAssignabilityCheck
json['promos'][project.minecraft.version + '-latest'] = project.version
//noinspection GroovyAssignabilityCheck
json['promos'][project.minecraft.version + '-recommended'] = project.version
if (!json.containsKey(project.minecraft.version)) json.put(project.minecraft.version, new HashMap<>())
//noinspection GroovyAssignabilityCheck
def version = json[project.minecraft.version]
version.put(project.version, runGitCommand("log -n 1 --format='%B'"))
updateFile.write JsonOutput.prettyPrint(JsonOutput.toJson(json)) // Pretty print cause why not, it's a small file anyway.
}
}
// Deobf jar allows people to drop this in mod folder on a dev environment
task deobfJar(type: Jar, dependsOn: 'jar') {
from sourceSets.main.output
classifier "deobf"
}
artifacts {
archives deobfJar // Default jars are already in there.
}
project.tasks.withType(Jar) { jarTask -> // For all jar tasks
jarTask.manifest {
attributes 'FMLAT': 'tfc_at.cfg' // See FML source code
attributes 'GIT_HASH': runGitCommand("log -n 1 --format='%H'")
attributes 'GIT_SUBJECT': runGitCommand("log -n 1 --format='%s'")
}
// Add "MC${mcversion}" to the jar, so the name ends up `TerraFirmaCraft-MC1.12.2-0.0.0.0.jar`
// This didn't used to have the `MC` prefix, but it confuses some hosting websites as the actual version numbers then.
jarTask.appendix = "MC" + project.minecraft.version
}
// If the keystore properties are installed (in ~/.gradle/gradle.properties) only.
// Only really relevant on the build server, but usable in dev also.
task signJar(type: SignJar, dependsOn: reobfJar) {
if (!project.hasProperty("signjar.keystore")) return
keyStore = project.getProperty("signjar.keystore")
alias = project.getProperty("signjar.alias")
storePass = project.getProperty("signjar.storePass")
keyPass = project.getProperty("signjar.keyPass")
inputFile = jar.archivePath
outputFile = jar.archivePath
}
// If the keystore properties are installed (in ~/.gradle/gradle.properties) only.
// Only really relevant on the build server, but usable in dev also.
// Makes it so you don't have to add the sign task in the command line, building will do.
if (project.hasProperty("signjar.keystore"))
{
build.dependsOn signJar
// Makes curseforge upload the signed jar
tasks.curseforge.mustRunAfter signJar
tasks.curseforge.dependsOn build
}
// Allow automatic uploading to curseforge
curseforge {
def envApiKey = System.getenv('CURSEFORGE_API_KEY')
if (envApiKey == null) {
println 'No Curseforge API Key'
envApiKey = 'kaput'
return
}
project {
apiKey = envApiKey
id = '302973'
changelog = "[Release Notes ${version}](https://github.com/TerraFirmaCraft/TerraFirmaCraft/releases/tag/v${version})"
changelogType = "markdown"
releaseType = 'release'
addGameVersion "${mcVersion}"
}
options {
javaVersionAutoDetect = false
}
}