generated from CRModders/Flux-Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
303 lines (247 loc) · 9.26 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id "maven-publish"
id "application"
id "java-library"
id "com.github.johnrengelman.shadow" version "8.1.1"
}
repositories {
ivy {
name "Cosmic Reach"
url "https://cosmic-archive.netlify.app/"
patternLayout {
artifact "/Cosmic Reach-[revision].jar"
}
// This is required in Gradle 6.0+ as metadata file (ivy.xml) is mandatory
metadataSources {
artifact()
}
content {
includeGroup "finalforeach"
}
}
ivy {
// The game provider for Fabric (equivalent of Cosmic Quilt for Fabric)
name "Galactic Loader"
url "https://github.com/GalacticLoader/GalacticLoader/releases/download/"
patternLayout {
artifact "/[revision]/GalacticLoader-[revision].jar"
}
// This is required in Gradle 6.0+ as metadata file (ivy.xml) is mandatory
metadataSources {
artifact()
}
content {
includeGroup "galacticloader"
}
}
maven {
name "crmoddersRepoReleases"
url "https://maven.crmodders.dev/releases"
}
maven {
name "JitPack"
url "https://jitpack.io"
}
maven {
name "Quilt"
url "https://maven.quiltmc.org/repository/release"
}
maven {
name "Fabric"
url "https://maven.fabricmc.net/"
}
maven {
name "Sponge"
url "https://repo.spongepowered.org/maven/"
}
mavenCentral()
}
configurations {
cosmicreach // Config to provide the Cosmic Reach project
compileOnly.extendsFrom(cosmicreach) // Allows cosmic reach to be used in the codebase
shadowMe // Allows specifying which stuff gets shadowed
api.extendsFrom(shadowMe)
internal { // Allows to include something without it being in the maven
visible = false
canBeConsumed = false
canBeResolved = false
}
compileClasspath.extendsFrom(internal)
runtimeClasspath.extendsFrom(internal)
testCompileClasspath.extendsFrom(internal)
testRuntimeClasspath.extendsFrom(internal)
gameMod // Config to be able to load Fabric Mods (Quilt loads mods from the classpath)
internal.extendsFrom(gameMod)
}
shadowJar {
configurations = [project.configurations.shadowMe]
archiveFileName = "${name}-${version}.jar"
mainClassName = "dev.crmodders.flux.FluxAPI"
}
dependencies {
// Cosmic Reach jar
cosmicreach("finalforeach:cosmicreach:${cosmic_reach_version}")
// Fabric Loader (for accessing its stuff in the code)
compileOnly("net.fabricmc:fabric-loader:${fabric_loader_version}") // Include the base Fabric Loader so we can only use classes from that
compileOnly("net.fabricmc:sponge-mixin:0.12.5+mixin.0.8.5")
compileOnly("io.github.llamalad7:mixinextras-fabric:0.3.5")
// FluxAPI
gameMod("dev.crmodders:fluxapi:${flux_version}")
}
processResources {
def resourceTargets = [ // Locations of where to inject the properties
"fabric.mod.json",
"quilt.mod.json"
]
// Left item is the name in the target, right is the variable name
def replaceProperties = [
"mod_version" : project.version,
"mod_name" : project.name,
"mod_id" : id,
"mod_desc" : description,
"mod_group" : project.group,
"cosmic_reach_version" : cosmic_reach_version,
]
inputs.properties replaceProperties
replaceProperties.put "project", project
filesMatching(resourceTargets) {
expand replaceProperties
}
}
// Sets up all the fabric mods (quilt's mods are gotten through the classpath)
static def String getModLocations(Configuration config) {
StringBuilder sb = new StringBuilder()
for (obj in config.allDependencies) {
sb.append(File.pathSeparator + config.files(obj)[0])
}
return sb.toString()
}
// Sets the current working path
static def void setCurWorkingDir(Task curTask) {
// Change the run directory
File runningDir = new File("run/")
if (!runningDir.exists())
runningDir.mkdirs()
curTask.workingDir = runningDir
}
tasks.register("runQuilt", JavaExec) {
group = "runs" // Sets the task's group
dependsOn "shadowJar" // To run this project in the game, depend on the creation of jar task
dependencies {
// Cosmic Quilt
implementation("org.codeberg.CRModders:cosmic-quilt:${cosmic_quilt_version}")
}
jvmArgs = [
"-Dloader.gameJarPath=" + configurations.cosmicreach.asPath, // Defines path to Cosmic Reach
"-Dloader.addMods=" +
shadowJar.archiveFile.get().asFile + // Add the jar of this project (using shadow on Fabric)
getModLocations(configurations.gameMod) // Adds the jars of any Quilt or Fabric mods added (only needed for Fabric as it doesnt load stuff from classpath)
]
setCurWorkingDir(tasks.runQuilt)
classpath = sourceSets.main.runtimeClasspath
mainClass = "org.quiltmc.loader.impl.launch.knot.KnotClient" // Quilt's main class
}
tasks.register("runFabric", JavaExec) {
group = "runs" // Sets the task's group
dependsOn "shadowJar" // Fabric doesnt search classpaths correctly, so we use the shadowed jar
dependencies {
// Galactic Loader
implementation("galacticloader:galacticloader:${fabric_loader_version}")
// Fabric Loader and its stuff
implementation("net.fabricmc:fabric-loader:${fabric_loader_version}")
implementation("net.fabricmc:tiny-mappings-parser:0.2.2.14")
implementation("net.fabricmc:access-widener:2.1.0")
implementation("net.fabricmc:sponge-mixin:0.12.5+mixin.0.8.5")
implementation("org.ow2.asm:asm:9.6")
implementation("org.ow2.asm:asm-util:9.6")
implementation("org.ow2.asm:asm-tree:9.6")
implementation("org.ow2.asm:asm-analysis:9.6")
implementation("org.ow2.asm:asm-commons:9.6")
implementation("io.github.llamalad7:mixinextras-fabric:0.3.5")
}
jvmArgs = [
"-Dfabric.skipMcProvider=true", // Stops Fabric from attempting to find mappings, and all the other Minecraft stuff
"-Dfabric.gameJarPath=" + configurations.cosmicreach.asPath, // Defines path to Cosmic Reach
"-Dfabric.addMods=" +
shadowJar.archiveFile.get().asFile + // Add the jar of this project (using shadow on Fabric)
getModLocations(configurations.gameMod) // Adds the jars of any Quilt or Fabric mods added (only needed for Fabric as it doesnt load stuff from classpath)
]
setCurWorkingDir(tasks.runFabric)
classpath = sourceSets.main.runtimeClasspath // Loads all the classpaths
mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient" // Fabric's main class
}
java {
withSourcesJar()
// withJavadocJar() // If docs are included with the project, this line can be un-commented
// Sets the Java version
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.register("buildJars") {
group = "compile"
dependsOn("buildFatJar")
dependsOn("buildSlimJar")
dependsOn("buildSourcesJar")
}
tasks.register("buildFatJar", ShadowJar) {
group = "compile"
configurations = [project.configurations.shadowMe]
dependsOn("compileJava")
dependsOn("processResources")
from(processResources.destinationDir)
from(sourceSets.main.java.classesDirectory)
archiveFileName = "${id}-${version}-fat.jar"
}
tasks.register("buildSlimJar", Jar) {
group = "compile"
dependsOn("compileJava")
dependsOn("processResources")
from(sourceSets.main.java.classesDirectory)
archiveFileName = "${id}-${version}-slim.jar"
}
tasks.register("buildSourcesJar", Jar) {
group = "compile"
from(sourceSets.main.allSource)
archiveFileName = "${id}-${version}-sources.jar"
}
publishing {
repositories {
maven {
name = "crmReleases"
url = "https://maven.crmodders.dev/releases"
credentials{
username = System.getenv("CRMReleasesUsername")
password = System.getenv("CRMReleasesPassword")
}
authentication {
basic(BasicAuthentication)
}
}
maven {
name = "crmSnapshots"
url = "https://maven.crmodders.dev/snapshots"
credentials{
username = System.getenv("CRMSnapshotsUsername")
password = System.getenv("CRMSnapshotsPassword")
}
authentication {
basic(BasicAuthentication)
}
}
}
assemble.dependsOn buildSourcesJar, buildFatJar, buildSlimJar
publications {
maven(MavenPublication) {
groupId = group
if (System.getenv("COMMIT_ID") != null) {
artifactId = System.getenv("COMMIT_ID")
} else {
artifactId = id
}
artifact buildFatJar
artifact source: buildSlimJar, classifier: 'slim', extension: 'jar'
artifact source: buildSourcesJar, classifier: 'source', extension: 'jar'
}
}
}