-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
294 lines (242 loc) · 8.67 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
/*
* CosmicDan's Mods build script
* Additional credits to SlimeKnights, aidancbrady and Choonster
* TODO: Adapt the script to be more universal (i.e. working with contributors via only build.properties changes - not just CosmicDan's main dev machine)
*/
buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
plugins {
id 'io.franzbecker.gradle-lombok' version '1.14'
id 'com.github.johnrengelman.shadow' version '1.2.4'
}
apply plugin: 'net.minecraftforge.gradle.forge'
project.logger.lifecycle("")
project.logger.lifecycle("---------------------------------")
project.logger.lifecycle("[#] CosmicDan's Mods Build Script")
project.logger.lifecycle("---------------------------------")
project.logger.lifecycle("")
/////////////////////////////////////////
// Assign properties and build config
/////////////////////////////////////////
def propGetter(inputProp) {
def inputPropFile = file inputProp
inputPropFile.withReader {
def prop = new Properties()
prop.load(it)
def outputProp = new ConfigSlurper().parse prop
return outputProp
}
}
ext.buildProps = propGetter("build.properties")
ext.versionProps = propGetter("version.properties")
ext.cosmiclibVersionProps = propGetter("../CosmicLib/version.properties")
group = buildProps.group_prefix + '.' + buildProps.modid
ext.groupAsPath = group.replace(".", "/")
ext.coreModPluginClass = (group + '.' + buildProps.coremod_package_suffix + '.' + buildProps.coremod_class)
ext.coreModPluginPath = 'src/main/java/' + coreModPluginClass.replace(".", "/") + '.java'
ext.coreModFound = false
try {
if (file(coreModPluginPath).exists()) { ext.coreModFound = true }
} catch(Exception e) {}
ext.accessTransformerName = buildProps.modid + "_at.cfg"
ext.accessTransformerPath = "src/main/resources/META-INF/${accessTransformerName}"
ext.accessTransformerFound = false
if (file(accessTransformerPath).exists()) { ext.accessTransformerFound = true }
/////////////////////////////////////////
// Store keystore password (do it early so build can fail early)
/////////////////////////////////////////
ext.keystorePassword = ""
try {
ext.keystorePassword = new File(buildProps.keyStorePasswordFile).text
} catch(Exception e) {
def errorMsg = "[!] Could not access file: " + buildProps.keyStorePasswordFile
logger.error(errorMsg)
throw e
}
/////////////////////////////////////////
// Print detected mod info
/////////////////////////////////////////
project.logger.lifecycle("[i] modId: " + buildProps.modid)
project.logger.lifecycle("[i] group: " + group)
project.logger.lifecycle("[i] coreModFound: " + coreModFound)
if (coreModFound) {
project.logger.lifecycle(" [~] coreModPluginClass: " + coreModPluginClass)
project.logger.lifecycle(" [~] coreModPluginPath: " + coreModPluginPath)
}
project.logger.lifecycle("[i] accessTransformerFound: " + accessTransformerFound)
if (accessTransformerFound) {
project.logger.lifecycle(" [~] accessTransformerName: " + accessTransformerName)
project.logger.lifecycle(" [~] accessTransformerPath: " + accessTransformerPath)
}
project.logger.lifecycle("[i] Keystore location: " + buildProps.keyStore)
project.logger.lifecycle("[i] Keystore alias: " + buildProps.keyStoreAlias)
project.logger.lifecycle("[i] Keystore password file: " + buildProps.keyStorePasswordFile)
project.logger.lifecycle("")
/////////////////////////////////////////
// Build version data/strings
/////////////////////////////////////////
task buildInfo {
def cmd = "git rev-parse --short HEAD"
def proc = cmd.execute()
proc.waitFor()
if (proc.exitValue() == 0) {
ext.revision = proc.text.trim()
} else {
ext.revision = "GITBORK"
}
ext.buildNum = "testbuild.${project.buildInfo.revision}"
}
ext.jarVersion = 'NFG'
ext.cosmicmod_releasemode = System.getenv("COSMICMOD_RELEASEMODE")
ext.baseVersion = "${versionProps.major}.${versionProps.minor}.${versionProps.revision}"
if ("${cosmicmod_releasemode}" != "null") {
if ("${cosmicmod_releasemode}" != "RELEASE") {
// append the ALPHA/BETA/DEV tag if it's not RELEASE mode
jarVersion = "${baseVersion}.${cosmicmod_releasemode}"
} else {
// Release mode
jarVersion = "${baseVersion}"
}
} else {
jarVersion = "${baseVersion}.${project.buildInfo.buildNum}"
}
version = "${buildProps.minecraft_version}-${jarVersion}"
/////////////////////////////////////////
// Common ForegeGradle stuff
/////////////////////////////////////////
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
minecraft {
version = "${buildProps.forge_version}"
runDir = "run"
mappings = "${buildProps.mcp_mappings}"
makeObfSourceJar = false
replace "@jar_fingerprint@", "${buildProps.signature_sha1}"
replace "@version@", "${baseVersion}"
project.logger.lifecycle("")
project.logger.lifecycle("[i] Parsing IDE config...")
if (coreModFound) {
project.logger.lifecycle(" [~] FakeCoreMod present; plugin found for IDE's JVM args:")
project.logger.lifecycle(" ${coreModPluginClass}")
clientJvmArgs += "-Dfml.coreMods.load=${coreModPluginClass}"
serverJvmArgs += "-Dfml.coreMods.load=${coreModPluginClass}"
} else {
project.logger.lifecycle(" [~] No CoreModCompanion found")
}
if (buildProps.username != "null") {
project.logger.lifecycle(" [~] Username found for IDE's run args:")
project.logger.lifecycle(" ${buildProps.username}")
clientRunArgs += "--username ${buildProps.username}"
} else {
project.logger.lifecycle(" [~] No username set. Will be random!")
}
project.logger.lifecycle("")
}
dependencies {
compileOnly "org.projectlombok:lombok:1.18.0"
compile 'com.fasterxml.jackson.core:jackson-core:2.9.5'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.5'
//compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
testCompile "junit:junit:4.12"
}
/////////////////////////////////////////
// Build task definitions
/////////////////////////////////////////
// Thanks to Choonster for mentioning shadowJar as an alternative to shading
shadowJar {
relocate 'com.fasterxml.jackson', 'com.cosmicdan.shadowed.com.fasterxml.jackson'
classifier '' // Replace the default JAR
}
reobf {
shadowJar {} // Reobfuscate the shadowed JAR
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", baseVersion
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':baseVersion, 'mcversion':project.minecraft.version
}
// copy everything else except the mcmod.info and coremod
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
// Main jar
jar {
archiveName = "${project.name}___FULL-DO-NOT-DISTRIB___${project.version}.jar"
finalizedBy reobfJar
manifest {
attributes (
'FMLCorePlugin': coreModPluginClass,
'FMLCorePluginContainsFMLMod': 'true'
)
}
}
// Deobfuscated (dev) jar
task deobfJar(type: Jar) {
archiveName = "${project.name}-DEV-ONLY-${project.version}-full-deobf.jar"
from sourceSets.main.output
classifier = 'deobf'
manifest {
if (accessTransformerFound) {
attributes 'FMLAT': accessTransformerName
}
}
}
// Sources jar
task sourceDeobfJar(type: Jar) {
archiveName = "${project.name}-DEV-ONLY-${project.version}-full-src.jar"
from sourceSets.main.resources.srcDirs
from sourceSets.main.allJava
classifier = 'sources'
}
// Sign jar task template
def signJars(jarToSign) {
return tasks.create(name: "sign${jarToSign.classifier}Jar", type: SignJar, dependsOn: jarToSign) {
keyStore = buildProps.keyStore
alias = buildProps.keyStoreAlias
storePass = keystorePassword
keyPass = keystorePassword
inputFile = jarToSign.archivePath
outputFile = jarToSign.archivePath
}
}
// Distrib or "release"
task mainJar(type: Jar) {
archiveName = "${project.name}-${project.version}.jar"
classifier "main"
dependsOn "extractAnnotationsJar"
manifest {
if (accessTransformerFound) {
attributes 'FMLAT': accessTransformerName
}
}
}
/////////////////////////////////////////
// Build task actions
/////////////////////////////////////////
artifacts {
archives deobfJar
archives sourceDeobfJar
archives mainJar
}
build {
dependsOn signJars(mainJar)
}
lombok {
version = "1.18.0"
sha256 = ""
}