forked from TerraFirmaCraft/TerraFirmaCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
236 lines (213 loc) · 8.23 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
/*
* 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
plugins {
id 'java'
id 'idea'
id 'java-library'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.33'
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
// 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 = config.mod.version
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!
mcVersion = config.minecraft.version
username = 'Developer'
useDependencyAccessTransformers = true
extraRunJvmArguments.addAll("-Xms1024m", "-Xmx3072m")
}
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/"
}
maven {
url "https://cursemaven.com"
}
}
String mcVersion = config.minecraft.version
String shortVersion = mcVersion.substring(0, mcVersion.lastIndexOf('.'))
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}"
implementation rfg.deobf("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
compileOnly "curse.maven:hwyla-253449:2568751"
compileOnly rfg.deobf("mcjty.theoneprobe:TheOneProbe-${shortVersion}:${config.TOP.version}")
compileOnly rfg.deobf("vazkii.patchouli:Patchouli:${config.patchouli.version}")
}
for (File at : sourceSets.getByName("main").resources.files) {
if (at.name.toLowerCase().endsWith("_at.cfg")) {
tasks.deobfuscateMergedJarToSrg.accessTransformerFiles.from(at)
tasks.srgifyBinpatchedJar.accessTransformerFiles.from(at)
}
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", version
inputs.property "mcversion", config.minecraft.version
filesMatching(['mcmod.info', 'pack.mcmeta']) { fcd ->
fcd.expand (
'mod_version': project.version,
'mc_version': project.minecraft.version
)
}
// Make sure Access Transformer files are in META-INF folder
rename '(.+_at.cfg)', 'META-INF/$1'
// from the project root, include the LICENSE file
from('.') {
include "LICENSE.txt"
}
// 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
tasks.register('deobfJar', Jar) {
dependsOn 'jar'
from sourceSets.main.output
archiveClassifier = "deobf"
}
artifacts {
archives deobfJar // Default jars are already in there.
}
project.tasks.withType(Jar).configureEach { 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.archiveAppendix = "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
}
}
*/