-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
375 lines (324 loc) · 16 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
buildscript {
repositories {
if (!project.hasProperty("forgeGradleBinFolder")) {
maven { url = 'https://files.minecraftforge.net/maven' }
}
if (!project.hasProperty("mixinGradleBinFolder")) {
maven { url = 'https://repo.spongepowered.org/maven' }
}
jcenter()
mavenCentral()
}
dependencies {
if (!project.hasProperty("forgeGradleBinFolder")) {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
} else {
compile files(project.getProperty("forgeGradleBinFolder").toString())
}
if (!project.hasProperty("mixinGradleBinFolder")) {
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
} else {
compile files(project.getProperty("mixinGradleBinFolder").toString())
}
if (project.hasProperty("mixinBinFolder")) {
compile files(project.getProperty("mixinBinFolder").toString())
}
}
}
plugins {
id 'java'
}
apply plugin: 'eclipse'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
import net.minecraftforge.gradle.common.task.SignJar
// Only edit below this line, any code above is needed for Mixin and Forge
apply plugin: 'maven-publish'
// Your mod configuration
def displayname = "Example Mod" // Display name
def classname = "ExampleMod" // Main java class name
def modid = "examplemod" // Mod id, lowercase letters only (once changed, you need to rename the mixins.examplemod.json to mixins.<new mod id>.json in the src/main/resources folder and also in more locations)
def vendor = "The Example Organization" // Vendor name
def credits = "John and Jane of Example.com" // Credits (can be whatever you want, optional, make empty to disable)
def authors = "John and Jane Doe" // Authors (can be whatever you want, optional, make empty to disable)
group = "com.example.${modid}" // Mod group, please share with package, see: http://maven.apache.org/guides/mini/guide-naming-conventions.html
def groupslashed = project.group.replaceAll("\\.", "/") // Mod group, this time, slashes instead of dots
version = "1.0" // Mod version
def mixinversion = "0.8.2" // Mixin target version
def minimal_mixinversion = "0.7.10" // Minimum mixin version
def MC_VER = "1.16.4" // Minecraft version (note that you need to change mappings if you change this)
def FORGE = "35.1.3" // Forge version (note that you need to change mappings if you change this)
def license = "GPL v3" // License (review options at: https://choosealicense.com/, must be open source due to coremod policies)
def issuetracker = "http://example.com/tracker" // Issue tracker url (optional, remove from mods.toml to disable)
def page = "http://example.com/" // Mod webpage url (optional, make empty to disable, remove from mods.toml to disable)
def updatejson = "http://example.com/update.json" // Mod update json url (optional, make empty to disable, remove from mods.toml to disable)
def logofile = "${modid}.png" // Mod logo file (optional, make empty to disable, remove from mods.toml to disable, file must be in the src/main/resources folder)
def description = '''
This is a long form description of the mod. You can write whatever you want here
Have some lorem ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
'''// Optional mod description (credits to forge, whatever is written there, make empty to disable, remove from mods.toml to disable)
def forgeversion = "${MC_VER}-${FORGE}" // Full forge version
archivesBaseName = "$modid" // Base name of the jar file
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20201028-1.16.3'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
}
}
dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft "net.minecraftforge:forge:${forgeversion}"
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// These dependencies get remapped to your current MCP mappings
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
compile "org.spongepowered:mixin:${mixinversion}"
annotationProcessor("org.spongepowered:mixin:${mixinversion}:processor")
}
eclipseClasspath.dependsOn classes // Fix for eclipse file generation
classes.dependsOn extractNatives // Make sure the natives are extracted on compile
// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"MixinConfigs": "mixins.${modid}.json",
"FMLCorePluginContainsFMLMod": "true",
"Specification-Title": "${modid}",
"Specification-Vendor": "${vendor}",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"${vendor}",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
}
}
repositories {
maven {
url "file:///${project.projectDir}/mcmodsrepo"
}
}
}
// Mixin refmap generation
mixin {
add sourceSets.main, "mixins.${modid}.refmap.json"
}
// Process resources
processResources {
// Make sure the task gets run if the properties change
inputs.property "modid", "${modid}".toString()
inputs.property "version", project.version
inputs.property "mcversion", "${MC_VER}".toString()
inputs.property "forgeversion", "${FORGE}".toString()
inputs.property "mixinver", "${mixinversion}".toString()
inputs.property "minmixin", "${minimal_mixinversion}".toString()
inputs.property "vendor", "${vendor}".toString()
inputs.property "authors", "${authors}".toString()
inputs.property "credits", "${credits}".toString()
inputs.property "display", "${displayname}".toString()
inputs.property "license", "${license}".toString()
inputs.property "page", "${page}".toString()
inputs.property "issuetracker", "${issuetracker}".toString()
inputs.property "updatejson", "${updatejson}".toString()
inputs.property "logofile", "${logofile}".toString()
inputs.property "description", "${description}".toString()
inputs.property "group", project.group
inputs.property "classname", "${classname}".toString()
inputs.property "groupslashed", "${groupslashed}".toString()
from(sourceSets.main.resources.srcDirs) {
expand 'modid': "${modid}".toString(), 'version': project.version, 'mcversion': "${MC_VER}".toString(), 'forgeversion': "${FORGE}".toString(), 'mixinver': "${mixinversion}".toString(), 'minmixin': "${minimal_mixinversion}".toString(), 'vendor': "${vendor}".toString(), 'authors': "${authors}".toString(), 'credits': "${credits}".toString(), 'display': "${displayname}".toString(), 'license': "${license}".toString(), 'page': "${page}".toString(), 'issuetracker': "${issuetracker}".toString(), 'updatejson': "${updatejson}".toString(), 'logofile': "${logofile}".toString(), 'description': "${description}".toString(), 'group': project.group, 'classname': "${classname}".toString(), 'groupslashed': "${groupslashed}".toString()
}
}
// Workaround for eclipse runs, this copies the resources and the classes to bin
task copyToBinDefault(type: Sync, dependsOn: classes) {
// Check if task is up to date
inputs.property "modid", "${modid}".toString()
inputs.property "version", project.version
inputs.property "mcversion", "${MC_VER}".toString()
inputs.property "forgeversion", "${FORGE}".toString()
inputs.property "mixinver", "${mixinversion}".toString()
inputs.property "minmixin", "${minimal_mixinversion}".toString()
inputs.property "vendor", "${vendor}".toString()
inputs.property "authors", "${authors}".toString()
inputs.property "credits", "${credits}".toString()
inputs.property "display", "${displayname}".toString()
inputs.property "license", "${license}".toString()
inputs.property "page", "${page}".toString()
inputs.property "issuetracker", "${issuetracker}".toString()
inputs.property "updatejson", "${updatejson}".toString()
inputs.property "logofile", "${logofile}".toString()
inputs.property "description", "${description}".toString()
inputs.property "group", project.group
inputs.property "classname", "${classname}".toString()
inputs.property "groupslashed", "${groupslashed}".toString()
// Copy input/output
from "$buildDir/resources/main"
into "bin/default/resources"
from "$buildDir/classes/java/main"
into "bin/default"
}
copyToBinDefault.finalizedBy('copyToBinMain')
// Workaround for eclipse runs, this copies the resources and the classes to bin
task copyToBinMain(type: Sync, dependsOn: classes) {
// Check if task is up to date
inputs.property "modid", "${modid}".toString()
inputs.property "version", project.version
inputs.property "mcversion", "${MC_VER}".toString()
inputs.property "forgeversion", "${FORGE}".toString()
inputs.property "mixinver", "${mixinversion}".toString()
inputs.property "minmixin", "${minimal_mixinversion}".toString()
inputs.property "vendor", "${vendor}".toString()
inputs.property "authors", "${authors}".toString()
inputs.property "credits", "${credits}".toString()
inputs.property "display", "${displayname}".toString()
inputs.property "license", "${license}".toString()
inputs.property "page", "${page}".toString()
inputs.property "issuetracker", "${issuetracker}".toString()
inputs.property "updatejson", "${updatejson}".toString()
inputs.property "logofile", "${logofile}".toString()
inputs.property "description", "${description}".toString()
inputs.property "group", project.group
inputs.property "classname", "${classname}".toString()
inputs.property "groupslashed", "${groupslashed}".toString()
// Copy input/output
from "$buildDir/resources/main"
into "bin/main/resources"
from "$buildDir/classes/java/main"
into "bin/main"
}
classes.finalizedBy('copyToBinDefault')
// Configure eclipse
eclipse {
project {
// Set project natures
natures.clear()
natures "org.eclipse.buildship.core.gradleprojectnature", "org.eclipse.jdt.core.javanature"
// Clear old builders and add new gradle builder
buildCommands.clear()
buildCommand "LaunchConfigHandle": "<project>/builders/Gradle Builder.launch", "org.eclipse.ui.externaltools.ExternalToolBuilder"
}
classpath {
file {
pathVariables 'GRADLE_HOME': file("${projectDir}")
whenMerged { classpath ->
classpath.getEntries().forEach { entry ->
if (entry.getKind() == "src" && entry.hasProperty("output")) {
entry.output = null // make sure the entry won't get compiled by java and instead by gradle.
}
}
}
}
}
}
// Make the clean task remove the run and logs folder
clean {
delete "run"
delete "logs"
}
// Make sure the cleanEclipse task removes the bin and settings folder (and the runs)
cleanEclipse {
delete ".settings"
delete "bin"
delete fileTree("$projectDir") {
include '*.launch'
}
}
// Task to clean all files, including eclipse
task cleanAll (type: Delete) {
delete ".factorypath"
delete "Patches"
}
cleanAll.dependsOn cleanEclipse
cleanAll.finalizedBy clean
// Copy the pre-configured jdt-apt config as a workaround to prevent a bug.
task copyEclipseConfig {
onlyIf { return !file(".settings/org.eclipse.jdt.apt.core.prefs").exists() }
copy {
from "config presets"
into ".settings"
include "org.eclipse.jdt.apt.core.prefs"
}
}
eclipseClasspath.dependsOn copyEclipseConfig
task signJar(type: SignJar, dependsOn: jar) {
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 loadKeyInfo {
onlyIf { return file("keyinfo.properties").exists() }
doFirst {
def props = new Properties()
props.load(new FileReader(file("keyinfo.properties")))
props.each { key, val ->
project.ext.set(key, val)
}
if (!project.hasProperty('keyStore')) throw new GradleException("Key information file 'keyinfo.properties' does not contain a keyStore variable, unable to continue.")
}
}
signJar.dependsOn loadKeyInfo