-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.gradle.kts
223 lines (200 loc) · 7.15 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
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
import me.modmuss50.mpp.ReleaseType
import net.fabricmc.loom.util.FileSystemUtil
import org.gradle.jvm.tasks.Jar
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import kotlin.io.path.deleteExisting
import kotlin.io.path.exists
plugins {
java
id("dev.architectury.loom") version "1.7-SNAPSHOT"
id("me.modmuss50.mod-publish-plugin") version "0.6.+"
id("net.neoforged.gradleutils") version "2.0.+"
}
val versionMc: String by rootProject
val versionForge: String by rootProject
val versionConnectorExtras: String by rootProject
val curseForgeId: String by project
val modrinthId: String by project
val githubRepository: String by project
val publishBranch: String by project
val connectorCurseForge: String by project
val connectorModrinth: String by project
val CI: Provider<String> = providers.environmentVariable("CI")
group = "dev.su5ed.sinytra"
version = "$versionConnectorExtras+$versionMc"
// Append git commit hash for dev versions
if (!CI.isPresent) {
version = "$version+dev-${gradleutils.gitInfo["hash"]}"
}
println("Project version: $version")
allprojects {
apply(plugin = "java")
apply(plugin = "dev.architectury.loom")
apply(plugin = "maven-publish")
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withSourcesJar()
}
repositories {
maven {
name = "NeoForge"
url = uri("https://maven.neoforged.net/releases")
}
maven {
name = "Sinytra"
url = uri("https://maven.su5ed.dev/releases")
}
maven {
name = "CurseMaven"
url = uri("https://cursemaven.com")
content {
includeGroup("curse.maven")
}
}
}
dependencies {
minecraft(group = "com.mojang", name = "minecraft", version = versionMc)
}
tasks {
jar {
manifest.attributes("Implementation-Version" to provider { project.version })
}
withType<net.fabricmc.loom.task.AbstractRemapJarTask> {
remapperIsolation.set(false)
}
}
afterEvaluate {
extensions.getByType<PublishingExtension>().run {
if (publications.isEmpty()) {
publications {
create<MavenPublication>("mavenJava") {
group = rootProject.group
from(components["java"])
}
}
}
}
}
}
subprojects {
afterEvaluate {
if (version == "unspecified") {
version = rootProject.version
logger.lifecycle("Setting default version of project $name to $version")
}
}
}
configurations.runtimeElements {
setExtendsFrom(listOf(configurations.include.get()))
}
dependencies {
mappings(loom.officialMojangMappings())
neoForge("net.neoforged:neoforge:$versionForge")
// includeProject("reach-entity-attributes")
includeProject("rei-bridge")
includeProject("emi-bridge")
includeProject("energy-bridge")
includeProject("terrablender-bridge")
includeProject("modmenu-bridge")
// includeProject("amecs-api")
// includeProject("forgeconfigapiport")
includeProject("extras-utils")
includeProject("kubejs-bridge")
includeProject("jei-bridge")
includeProject("pehkui-bridge")
// Misc
modImplementation("curse.maven:mcpitanlibarch-682213:5531565")
}
fun DependencyHandlerScope.includeProject(name: String) {
runtimeOnly(project(path = ":$name", configuration = "namedElements"))
api(include(project(":$name")) {
isTransitive = false
})
}
val relocateDirectory: Jar.(String, String) -> Unit by extra { from, to ->
doLast {
FileSystemUtil.getJarFileSystem(archiveFile.get().asFile.toPath(), false).use { fs ->
val fromPath = fs.getPath(from)
val toPath = fs.getPath(to)
Files.walk(fromPath).forEach {
Files.move(
it,
toPath.resolve(fromPath.relativize(it)).also { Files.createDirectories(it.parent) },
StandardCopyOption.COPY_ATTRIBUTES
)
}
Files.walk(fromPath).sorted(Comparator.reverseOrder()).forEach(Files::delete)
}
}
}
// Mitigate https://github.com/MinecraftForge/InstallerTools/issues/14 in fg.deobf
val relocateNestedJars by tasks.registering {
val archiveFile = tasks.remapJar.flatMap { it.archiveFile }
inputs.file(archiveFile)
outputs.upToDateWhen { true }
doLast {
FileSystemUtil.getJarFileSystem(archiveFile.get().asFile.toPath(), false).use { fs ->
val sourceDirectory = fs.getPath("META-INF", "jars")
if (sourceDirectory.exists()) {
val destinationDirectory = fs.getPath("META-INF", "jarjar")
Files.newDirectoryStream(sourceDirectory).forEach { path ->
Files.move(path, destinationDirectory.resolve(path.fileName), StandardCopyOption.COPY_ATTRIBUTES)
}
sourceDirectory.deleteExisting()
val metadata = fs.getPath("META-INF", "jarjar", "metadata.json")
val text = Files.readString(metadata, StandardCharsets.UTF_8)
val replaced = text.replace("META-INF/jars/", "META-INF/jarjar/")
Files.writeString(metadata, replaced, StandardCharsets.UTF_8)
}
}
}
}
tasks.remapJar {
finalizedBy(relocateNestedJars)
}
publishMods {
file.set(tasks.remapJar.flatMap { it.archiveFile })
changelog.set(providers.environmentVariable("CHANGELOG").orElse("# $version"))
type.set(providers.environmentVariable("PUBLISH_RELEASE_TYPE").orElse("alpha").map(ReleaseType::of))
modLoaders.add("neoforge")
dryRun.set(!CI.isPresent)
github {
accessToken.set(providers.environmentVariable("GITHUB_TOKEN"))
repository.set(githubRepository)
commitish.set(publishBranch)
}
curseforge {
accessToken.set(providers.environmentVariable("CURSEFORGE_TOKEN"))
projectId.set(curseForgeId)
minecraftVersions.add(versionMc)
requires {
slug.set(connectorCurseForge)
}
optional { slug.set("roughly-enough-items") }
optional { slug.set("emi") }
optional { slug.set("terrablender") }
optional { slug.set("architectury-api") }
optional { slug.set("geckolib") }
optional { slug.set("kubejs") }
optional { slug.set("jei") }
optional { slug.set("pehkui") }
}
modrinth {
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
projectId.set(modrinthId)
minecraftVersions.add(versionMc)
requires {
id.set(connectorModrinth)
}
optional { id.set("nfn13YXA") } // REI
optional { id.set("fRiHVvU7") } // EMI
optional { id.set("kkmrDlKT") } // TerraBlender
optional { id.set("lhGA9TYQ") } // Architectury API
optional { id.set("8BmcQJ2H") } // Geckolib
optional { id.set("umyGl7zF") } // KubeJS
optional { id.set("u6dRKJwZ") } // JEI
optional { id.set("t5W7Jfwy") } // Pehkui
}
}