-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
243 lines (202 loc) · 6.62 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
plugins {
id 'java'
// Plugin to put dependencies inside our final jar
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
// Plugin to create merged jars
id 'io.github.pacifistmc.forgix' version '1.2.9'
// Manifold preprocessor
id 'systems.manifold.manifold-gradle-plugin' version '0.0.2-alpha'
// Architectury is used here only as a replacement for forge's own loom
id 'dev.architectury.loom' version '1.6.396' apply false
}
/**
* Creates a list of values of Minecraft versions for the Manifold preprocessors.
* Source: https://gitlab.com/jeseibel/distant-horizons/-/blob/870c0f68d3faf6aa7c76a1c094d19c802f59f06b/build.gradle
*
* @param mcVersions array of all MC versions
* @param targetMinecraftIndex array index of the currently active MC version
*/
def writeBuildGradlePredefine(List<String> mcVersions, int targetMinecraftIndex)
{
StringBuilder sb = new StringBuilder()
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n")
for (int i = 0; i < mcVersions.size(); i++) {
String verStr = mcVersions[i].replace(".", "_")
sb.append("MC_" + verStr + "=" + i.toString() + "\n")
if (targetMinecraftIndex == i) {
sb.append("MC_VER=" + i.toString() + "\n")
}
}
new File(projectDir, "build.properties").text = sb.toString()
}
// Transfers the values set in settings.gradle to the rest of the project
project.gradle.ext.getProperties().each { prop ->
rootProject.ext.set(prop.key, prop.value)
println "Added prop [key:" + prop.key + ", value:" + prop.value + "]"
}
// Sets up manifold stuff
writeBuildGradlePredefine(rootProject.targetMinecraftVersions, rootProject.targetMinecraftVersionIndex)
rootProject.versionStr = rootProject.mod_version + '-' + rootProject.minecraft_version
rootProject.group = mod_group_id
forgix {
group = rootProject.group
mergedJarName = "${rootProject.mod_id}-${rootProject.versionStr}.jar"
if (findProject(':forge')) {
forge {
jarLocation = "build/libs/${rootProject.mod_id}-forge-${rootProject.versionStr}.jar"
}
}
if (findProject(':fabric')) {
fabric {
jarLocation = "build/libs/${rootProject.mod_id}-fabric-${rootProject.versionStr}.jar"
}
}
// TODO removeDuplicates causes a ClassNotFoundException with Forge.
// forge can't seem to find the common package when this is enabled.
// it would be good if we could use it since it downsizes the output .jar file quite a bit.
// removeDuplicate 'nl.nielspoldervaart.gdmc'
}
subprojects { p ->
def isMinecraftSubProject = p != project(':common')
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'systems.manifold.manifold-gradle-plugin'
if (
(findProject(':forge') && p == project(':forge')) ||
(findProject(':neoforge') && p == project(':neoforge'))
) {
apply plugin: 'dev.architectury.loom'
}
configurations {
shadowMe
implementation.extendsFrom(shadowMe)
if (isMinecraftSubProject) {
common
shadowCommon
shadowMe.extendsFrom(common)
compileClasspath.extendsFrom(common)
runtimeClasspath.extendsFrom(common)
if (findProject(':forge')) {
developmentForge.extendsFrom(common)
}
if (findProject(':fabric') && p != project(':fabric')) {
fabric
shadowFabric
compileClasspath.extendsFrom(fabric)
runtimeClasspath.extendsFrom(fabric)
}
}
}
dependencies {
annotationProcessor 'systems.manifold:manifold-preprocessor:2024.1.0'
if (isMinecraftSubProject) {
common(project(':common')) { transitive false }
shadowCommon(project(':common')) { transitive false }
if (findProject(':fabric') && p != project(':fabric')) {
fabric(project(path: ':fabric')) { transitive false }
shadowFabric(project(path: ':fabric')) { transitive false }
}
}
}
shadowJar {
configurations = [project.configurations.shadowMe]
mergeServiceFiles()
}
jar.dependsOn(shadowJar)
processResources {
def resourceTargets = [
// For Forge
"META-INF/mods.toml",
"fabric.mod.json",
]
def intoTargets = ["$buildDir/resources/main/"]
def replaceProperties = [
minecraft_version: rootProject.minecraft_version,
minecraft_version_range: rootProject.minecraft_version_range,
forge_version: rootProject.forge_version,
forge_version_range: rootProject.forge_version_range,
forge_loader_version_range: rootProject.forge_loader_version_range,
fabric_version: rootProject.fabric_version,
fabric_loader_version: rootProject.fabric_loader_version,
mod_id: rootProject.mod_id,
mod_name: rootProject.mod_name,
mod_license: rootProject.mod_license,
mod_version: rootProject.versionStr,
mod_authors: rootProject.mod_authors,
mod_description: rootProject.mod_description,
java_version: rootProject.java_version,
]
inputs.properties replaceProperties
replaceProperties.put 'project', project
filesMatching(resourceTargets) {
expand replaceProperties + [project: project]
}
intoTargets.each { target -> {
if (file(target).exists()) {
copy {
from(sourceSets.main.resources) {
include resourceTargets
expand replaceProperties
}
into target
}
}
}}
}
jar {
manifest {
attributes(
'Specification-Title' : rootProject.mod_id,
'Specification-Vendor' : rootProject.mod_authors,
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : project.name,
'Implementation-Version' : rootProject.versionStr,
'Implementation-Vendor' : rootProject.mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
)
}
}
}
allprojects { p -> {
apply plugin: 'java'
apply plugin: 'maven-publish'
archivesBaseName = rootProject.mod_id
version = project.name + '-' + rootProject.versionStr
group = rootProject.group
repositories {
mavenCentral()
// VanillaGradle and Mixins in common
maven {
url 'https://repo.spongepowered.org/maven/'
}
// For Architectury API
maven {
url 'https://maven.architectury.dev'
}
// Manifold
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
task copyCommonResources(type: Copy) {
from project(":common").file("src/main/resources")
into(file(p.file("build/resources/main")))
}
tasks.withType(JavaCompile).configureEach {
options.release = rootProject.java_version as Integer
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
options.compilerArgs += ['-Xplugin:Manifold']
}
java {
withSourcesJar()
}
}}
// Delete the merged folder when running clean
task cleanMergedJars() {
def mergedFolder = file('Merged')
if (mergedFolder.exists()) {
delete(mergedFolder)
}
}
// add cleanMergedJars to the end of the "clean" task
tasks['clean'].finalizedBy(cleanMergedJars)