-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
299 lines (259 loc) · 8.94 KB
/
build.gradle.kts
File metadata and controls
299 lines (259 loc) · 8.94 KB
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
import org.gradle.api.internal.artifacts.dependencies.DependencyVariant
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.gradle.ext.Gradle
import org.jetbrains.gradle.ext.compiler
import org.jetbrains.gradle.ext.runConfigurations
import org.jetbrains.gradle.ext.settings
plugins {
id("java")
id("java-library")
kotlin("jvm") version libs.versions.kotlin.get()
id("maven-publish")
id("eclipse")
alias(libs.plugins.ideaExt)
alias(libs.plugins.retrofuturaGradle)
alias(libs.plugins.curseGradle)
alias(libs.plugins.dokka)
alias(libs.plugins.shadow)
}
val embed = "embed"
group = modGroup
version = modVersion
// Mixed programming environment not supported Jabel or other same functional dependencies, we used Java 8
// as default. Do not change this settings otherwise you know what you are doing.
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
// Azul covers the most platforms for Java 8 toolchains, crucially including MacOS arm64.
vendor.set(JvmVendorSpec.AZUL)
}
// Generate sources and Javadocs jars when building and publishing.
// withSourcesJar()
}
kotlin {
jvmToolchain(8)
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
// Used specified sourceSet of two languages as default, should put all Java class in 'java' and all Kotlin
// class to 'kotlin' sourceSets. Do not change these settings, this is only for javaCompiler and kotlinCompiler.
sourceSets {
main {
java {
srcDir("src/main/java")
}
kotlin {
srcDir("src/main/kotlin")
}
}
}
configurations {
val embed = create(embed)
implementation {
extendsFrom(embed)
}
}
minecraft {
mcVersion.set(minecraftVersion)
mcpMappingChannel.set("stable")
mcpMappingVersion.set("39")
// Set username here, the UUID will be looked up automatically.
username.set(userName)
// Add any additional tweaker classes here.
// extraTweakClasses.add("org.spongepowered.asm.launch.MixinTweaker")
// Add various JVM arguments here for runtime.
val args = mutableListOf("-ea:${group}")
if (usesCoreMod.toBoolean()) {
args += "-Dfml.coreMods.load=$coreModPluginPath"
}
if (usesMixins.toBoolean()) {
args += "-Dmixin.hotSwap=true"
args += "-Dmixin.checks.interfaces=true"
args += "-Dmixin.debug.export=true"
}
// args += "-XXaltjvm=dcevm"
// args += "-XX:+AllowEnhancedClassRedefinition"
args += "-Dterminal.jline=true"
extraRunJvmArguments.addAll(args)
// Include and use dependencies' Access Transformer files
useDependencyAccessTransformers.set(true)
// Add any properties you want to swap out for a dynamic value at build time here.
// Any properties here will be added to a class at build time, the name can be configured below.
injectedTags.put("MOD_VERSION", modVersion)
injectedTags.put("MOD_ID", modId)
injectedTags.put("MOD_NAME", modName)
}
repositories()
dependencies {
if (usesMixins.toBoolean()) {
annotationProcessor(libs.asm)
annotationProcessor(libs.guava)
annotationProcessor(libs.gson)
val mixinBooter = modUtils.enableMixins(libs.mixinBooter, "mixins.${modId}.refmap.json") as Provider<*>
api(mixinBooter) {
isTransitive = false
}
annotationProcessor(mixinBooter) {
isTransitive = false
}
}
implementation(libs.forgelin) {
exclude("net.minecraftforge")
}
implementation(libs.modularui) {
isTransitive = false
}
api(libs.codeChickenLib)
api(libs.ctm)
implementation(deobf(files("libs/morphismlib-1.12.2-1.0.0.jar")))
implementation(deobf(files("libs/gregtech-1.12.2-master-#2901.jar")))
implementation(deobf(libs.ae2ExtendedLife))
implementation(libs.jei)
implementation(libs.theOneProbe)
compileOnly(libs.groovyScript) {
isTransitive = false
}
compileOnly(libs.craftTweaker2)
runtimeOnly(deobf(libs.catalogue))
compileOnlyApi(libs.jetbrainsAnnotations)
annotationProcessor(libs.jetbrainsAnnotations)
}
fun DependencyHandler.deobf(dependencyNotation: Any): Any {
if (dependencyNotation is Provider<*>) {
return deobf(dependencyNotation.get())
}
var depSpec = dependencyNotation
if (dependencyNotation is Dependency) {
depSpec = "${dependencyNotation.group}:${dependencyNotation.name}:${dependencyNotation.version}"
if (dependencyNotation is DependencyVariant) {
depSpec += ":${dependencyNotation.classifier}"
}
}
return rfg.deobf(depSpec)
}
// Adds Access Transformer files to tasks.
@Suppress("Deprecation")
if (usesAccessTransformer.toBoolean()) {
for (at in sourceSets.getByName("main").resources.files) {
if (at.name.toLowerCase().endsWith("_at.cfg")) {
tasks.deobfuscateMergedJarToSrg.get().accessTransformerFiles.from(at)
tasks.srgifyBinpatchedJar.get().accessTransformerFiles.from(at)
}
}
}
tasks {
// Generate a RFG Tags class.
injectTags {
outputClassName.set(generateTokenPath)
}
processIdeaSettings {
dependsOn(injectTags)
}
}
@Suppress("UnstableApiUsage")
tasks.withType<ProcessResources> {
// This will ensure that this task is redone when the versions change.
inputs.property("version", modVersion)
inputs.property("mcversion", minecraft.mcVersion)
// Replace various properties in mcmod.info and pack.mcmeta if applicable.
filesMatching(arrayListOf("mcmod.info", "pack.mcmeta")) {
expand(
"version" to modVersion,
"mcversion" to minecraft.mcVersion,
"modid" to modId
)
}
if (usesAccessTransformer.toBoolean()) {
rename("(.+_at.cfg)", "META-INF/$1") // Make sure Access Transformer files are in META-INF folder.
}
}
tasks.withType<Jar> {
manifest {
val attributeMap = mutableMapOf<String, String>()
if (usesCoreMod.toBoolean()) {
attributeMap["FMLCorePlugin"] = coreModPluginPath
if (includeMod.toBoolean()) {
attributeMap["FMLCorePluginContainsFMLMod"] = true.toString()
attributeMap["ForceLoadAsMod"] =
(project.gradle.startParameter.taskNames.getOrNull(0) == "build").toString()
}
}
if (usesAccessTransformer.toBoolean()) {
attributeMap["FMLAT"] = modId + "_at.cfg"
}
attributes(attributeMap)
}
}
// Shadowed external packages to internal packages to resolved class not found when
// the mod is running at other environments.
if (usesShadowJar.toBoolean()) {
tasks {
shadowJar {
configurations = listOf(project.configurations["embed"])
mergeServiceFiles()
mergeGroovyExtensionModules()
minimize()
}
reobfJar {
inputJar.set(shadowJar.get().archiveFile)
}
}
// Remove shadow jar from java component
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations.shadowRuntimeElements.get()) {
skip()
}
}
// Add JavaDocs/KDocs generate merger in Java/Kotlin mixed programming environment.
tasks.withType<DokkaTask> {
outputDirectory.set(projectDir.resolve("docs"))
dokkaSourceSets {
configureEach {
// Allowed Dokka read two sourceSets.
sourceRoots.from(file("src/main/java"), file("src/main/kotlin"))
}
}
}
idea {
module {
inheritOutputDirs = true
// IDEA no longer automatically downloads sources/javadoc jars for dependencies,
// so we need to explicitly enable the behavior.
isDownloadSources = true
isDownloadJavadoc = true
}
project {
settings {
runConfigurations {
add(Gradle("1. Run Client").apply {
setProperty("taskNames", listOf("runClient"))
})
add(Gradle("2. Run Server").apply {
setProperty("taskNames", listOf("runServer"))
})
add(Gradle("3. Run Obfuscated Client").apply {
setProperty("taskNames", listOf("runObfClient"))
})
add(Gradle("4. Run Obfuscated Server").apply {
setProperty("taskNames", listOf("runObfServer"))
})
}
compiler.javac {
afterEvaluate {
javacAdditionalOptions = "-encoding utf8"
moduleJavacAdditionalOptions = mutableMapOf(
(project.name + ".main") to tasks.compileJava.get().options.compilerArgs.joinToString(" ") { "\"$it\"" }
)
}
}
}
}
}
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}