forked from CaffeineMC/sodium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
146 lines (118 loc) · 4.18 KB
/
build.gradle.kts
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
object Constants {
// https://fabricmc.net/develop/
const val MINECRAFT_VERSION: String = "1.20.4"
const val FABRIC_LOADER_VERSION: String = "0.15.6"
const val FABRIC_API_VERSION: String = "0.96.4+1.20.4"
// https://semver.org/
const val MOD_VERSION: String = "0.6.0"
}
plugins {
// Unlike most projects, we choose to pin the specific version of Loom.
// This prevents a lot of issues where the build script can fail randomly because the Fabric Maven server
// is not reachable for some reason, and it makes builds much more reproducible. Observation also shows that it
// really helps to improve startup times on slow connections.
id("fabric-loom") version "1.5.7"
}
base {
archivesName = "sodium-fabric"
group = "net.caffeinemc.mods"
version = createVersionString()
}
loom {
mixin {
defaultRefmapName = "sodium.refmap.json"
}
accessWidenerPath = file("src/main/resources/sodium.accesswidener")
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
sourceSets {
val main = getByName("main")
val api = create("api")
val desktop = create("desktop")
api.apply {
java {
compileClasspath += main.compileClasspath
}
}
desktop.apply {
java {
srcDir("src/desktop/java")
}
}
main.apply {
java {
compileClasspath += api.output
runtimeClasspath += api.output
}
}
}
dependencies {
minecraft(group = "com.mojang", name = "minecraft", version = Constants.MINECRAFT_VERSION)
mappings(loom.officialMojangMappings())
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = Constants.FABRIC_LOADER_VERSION)
include(implementation(group = "com.lodborg", name = "interval-tree", version = "1.0.0"))
fun addEmbeddedFabricModule(name: String) {
val module = fabricApi.module(name, Constants.FABRIC_API_VERSION)
modImplementation(module)
include(module)
}
// Fabric API modules
addEmbeddedFabricModule("fabric-api-base")
addEmbeddedFabricModule("fabric-block-view-api-v2")
addEmbeddedFabricModule("fabric-renderer-api-v1")
addEmbeddedFabricModule("fabric-rendering-data-attachment-v1")
addEmbeddedFabricModule("fabric-rendering-fluids-v1")
addEmbeddedFabricModule("fabric-resource-loader-v0")
}
tasks {
getByName<JavaCompile>("compileDesktopJava") {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
jar {
from("${rootProject.projectDir}/COPYING")
from("${rootProject.projectDir}/COPYING.LESSER")
val api = sourceSets.getByName("api")
from(api.output.classesDirs)
from(api.output.resourcesDir)
val desktop = sourceSets.getByName("desktop")
from(desktop.output.classesDirs)
from(desktop.output.resourcesDir)
manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
}
processResources {
inputs.property("version", project.version)
filesMatching("fabric.mod.json") {
expand(mapOf("version" to project.version))
}
}
}
// 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"
}
fun createVersionString(): String {
val builder = StringBuilder()
val isReleaseBuild = project.hasProperty("build.release")
val buildId = System.getenv("GITHUB_RUN_NUMBER")
if (isReleaseBuild) {
builder.append(Constants.MOD_VERSION)
} else {
builder.append(Constants.MOD_VERSION.substringBefore('-'))
builder.append("-snapshot")
}
builder.append("+mc").append(Constants.MINECRAFT_VERSION)
if (!isReleaseBuild) {
if (buildId != null) {
builder.append("-build.${buildId}")
} else {
builder.append("-local")
}
}
return builder.toString()
}