-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
180 lines (147 loc) · 5.92 KB
/
build.gradle.kts
File metadata and controls
180 lines (147 loc) · 5.92 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
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.provideDelegate
import java.util.*
val modId: String by project
val modVersion: String by project
val mavenGroup: String by project
val minecraftVersion: String by project
val lambdaVersion: String by project
val yarnMappings: String by project
val fabricLoaderVersion: String by project
val fabricApiVersion: String by project
val kotlinFabricVersion: String by project
val classGraphVersion: String by project
val kotlinVersion: String by project
val mavenType: String by project
// The next lines are used to replace the version in the fabric.mod.json files
// You most likely don't want to touch this
val targets = listOf("fabric.mod.json")
val replacements = file("gradle.properties").inputStream().use { stream ->
Properties().apply { load(stream) }
}.map { (k, v) -> k.toString() to v.toString() }.toMap()
// This is the directory where you can put local libraries that will get indexed by Gradle
val libs = file("libs")
plugins {
kotlin("jvm") version "2.3.0"
id("org.jetbrains.dokka") version "2.1.0"
id("fabric-loom") version "1.14-SNAPSHOT"
id("com.gradleup.shadow") version "9.3.0"
id("maven-publish")
}
group = mavenGroup
version = modVersion
base.archivesName = modId
// We need to force it using lwjgl 3.3.3 because of 3.3.4 poor support for Wayland protocol
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.lwjgl") {
useVersion("3.3.3")
}
}
}
repositories {
mavenLocal() // Allow the use of local repositories
maven("https://maven.2b2t.vc/releases") // Baritone
maven("https://jitpack.io") // KDiscordIPC
mavenCentral()
if (mavenType == "snapshots") maven("https://maven.lambda-client.org/snapshots")
else maven("https://maven.lambda-client.org/releases")
// Allow the use of local libraries
flatDir {
dirs(libs)
}
}
loom {
accessWidenerPath = file("src/main/resources/$modId.accesswidener")
enableTransitiveAccessWideners = true
enableModProvidedJavadoc = true
runs {
all {
// These arguments are used to play with an account in your development environment. Because Minecraft doesn't refresh your token for you,
// you will have to change this every 24 hours.
programArgs("--username", "Steve", "--uuid", "8667ba71b85a4004af54457a9734eed7", "--accessToken", "****")
}
}
}
val includeLib: Configuration by configurations.creating
val includeMod: Configuration by configurations.creating
val shadowLib: Configuration by configurations.creating { isCanBeConsumed = false }
val shadowMod: Configuration by configurations.creating { isCanBeConsumed = false }
fun DependencyHandlerScope.setupConfigurations() {
// This configuration adds the dependency in the classpath and includes it in Fabric's jar-in-jar folder
includeLib.dependencies.forEach {
implementation(it)
include(it)
}
// This configuration adds the mod dependency in the classpath and includes it in Fabric's jar-in-jar folder
includeMod.dependencies.forEach {
modImplementation(it)
include(it)
}
// This configuration adds the dependency in the classpath and adds its content into the final jar
shadowLib.dependencies.forEach {
implementation(it)
}
// This configuration adds the mod dependency in the classpath and adds its content into the final jar
shadowMod.dependencies.forEach {
modImplementation(it)
}
}
dependencies {
// Read this if you'd like to understand the gradle dependency hell
// https://medium.com/@nagendra.raja/understanding-configurations-and-dependencies-in-gradle-ad0827619501
minecraft("com.mojang:minecraft:$minecraftVersion")
mappings("net.fabricmc:yarn:$minecraftVersion+$yarnMappings:v2")
// Add Kotlin
// If you wish to use additional Kotlin features, you can add them here
// You do not need to include them in the final jar since we are using
// Kotlin mod loaders which already includes them.
// implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
// Fabric
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion+$minecraftVersion")
modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion.$kotlinVersion")
// Lambda
if (mavenType == "snapshots") modImplementation("com.lambda:lambda:$lambdaVersion+$minecraftVersion-SNAPSHOT")
else modImplementation("com.lambda:lambda:$lambdaVersion+$minecraftVersion")
// This is the library we use for reflections.
// If you need to use it then simply uncomment this line.
//
// This library allows us to scan the classpath for classes.
//
// If you are new to programming or new to Java
// you may want to read this article on the classpath:
// https://medium.com/javarevisited/back-to-the-basics-of-java-part-1-classpath-47cf3f834ff
implementation("io.github.classgraph:classgraph:$classGraphVersion")
// Finish the configuration
setupConfigurations()
}
tasks {
shadowJar {
archiveClassifier = "dev-shadow"
archiveVersion = "$modVersion+$minecraftVersion"
configurations = listOf(shadowLib, shadowMod)
}
remapJar {
dependsOn(shadowJar)
inputFile = shadowJar.get().archiveFile
archiveVersion = "$modVersion+$minecraftVersion"
}
processResources {
filesMatching(targets) { expand(replacements) }
// Forces the task to always run
outputs.upToDateWhen { false }
}
}
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xcontext-parameters", "-Xconsistent-data-class-copy-visibility")
}
jvmToolchain(21)
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}