generated from FabricMC/fabric-example-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
157 lines (128 loc) · 4.75 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
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
// FIXME Replace with a newer version as soon as it releases.
classpath 'com.guardsquare:proguard-gradle:7.3.2'
}
}
plugins {
// TODO This buildscript currently depends on some implementation details of Loom due to dumb ProGuard stuff
// The version of Loom used will probably be able to be updated without any issues.
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
// Defines a Java 17 compatible JDK.
def compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
// Tells Gradle to use the previously defined Java 17 compatible JDK.
java {
toolchain {
compiler
}
}
// Tells Gradle to always compile with the previously defined Java 17 compatible JDK.
tasks.withType(JavaCompile).configureEach {
javaCompiler = compiler
}
archivesBaseName = project.archives_base_name
version = project.mod_version + "-" + project.minecraft_version
group = project.maven_group
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
}
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
// Minifies all .json files when building the mod.
// The source files are not minified, only the files in the resulting .jar.
// This both helps in reducing the size of the built .jar, and verifies that your .json files are valid each time you build.
// This script is from https://github.com/TelepathicGrunt/RepurposedStructures-Fabric/blob/82d579bb3e9a48859a0b2b1d78cc1ace5417d567/build.gradle#L84
doLast {
def jsonMinifyStart = System.currentTimeMillis()
def jsonMinified = 0
def jsonBytesSaved = 0
fileTree(dir: outputs.files.asPath, include: '**/*.json').each {
File file = it
jsonMinified++
def oldLength = file.length()
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
jsonBytesSaved += oldLength - file.length()
}
println('Minified ' + jsonMinified + ' json files. Saved ' + jsonBytesSaved + ' bytes. Took ' + (System.currentTimeMillis() - jsonMinifyStart) + 'ms.')
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// This task creates a .jar file containing a deobfuscated version of this mod, for ProGuard to minimise.
task unmappedJar(type: Jar) {
archiveClassifier = "unmapped"
from sourceSets.main.output
}
// TODO depends on loom implementation details I don't understand
task ('proguard', type: proguard.gradle.ProGuardTask) {
dependsOn "unmappedJar"
verbose
target "17"
// Workaround for ProGuard seemingly not recognising when the output .jar file doesn't exist
outputs.upToDateWhen { false }
injars "build/libs/" + archivesBaseName + "-" + version + "-unmapped.jar"
outjars "build/libs/" + archivesBaseName + "-" + version + "-dev" + ".jar"
// Get the Java standard library from the provided toolchain.
libraryjars compiler.get().metadata.installationPath.asFile.absolutePath + "/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
// Add relevant Minecraft libraries to ProGuard's list of libraries to obfuscate against.
// TODO this is very janky
libraryjars project.configurations.compileClasspath
// The rest of the configs are in this file
configuration 'guard.pro'
}
artifacts.add('archives', file(proguard.outputs.files.singleFile)) {
type('jar')
builtBy(proguard)
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
// TODO depends on loom implementation details I don't understand
remapJar {
dependsOn(proguard)
input.fileValue(proguard.outputs.files.singleFile)
//archiveClassifier.set("proguard")
}
build.finalizedBy(cleanUnmappedJar)
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
}