-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
253 lines (219 loc) · 7.54 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
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
@file:Suppress("PropertyName")
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import net.minecraftforge.gradle.userdev.DependencyManagementExtension
import net.minecraftforge.gradle.userdev.tasks.JarJar
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.util.*
plugins {
idea
eclipse
`maven-publish`
id("net.minecraftforge.gradle")
id("org.spongepowered.mixin")
id("org.parchmentmc.librarian.forgegradle")
}
// region helpers
val modGroup: String by project
val modId: String by project
val modName: String by project
val modVersion: String by project
val modAuthors: String by project
val githubRepo: String by project
val javaVersion: String by project
val mixinVersion: String by project
val mappingsChannel: String by project
val mappingsVersion: String by project
val mcVersion: String by project
val forgeVersion: String by project
val vendor: String by project
val issueTrackerUrl by extra("https://github.com/${githubRepo}/issues")
val SourceSetContainer.api: NamedDomainObjectProvider<SourceSet>
get() = named("api")
val SourceSetContainer.data: NamedDomainObjectProvider<SourceSet>
get() = named("data")
val Provider<SourceSet>.output: Provider<SourceSetOutput>
get() = map { it.output }
val Provider<SourceSet>.allSource: Provider<SourceDirectorySet>
get() = map { it.allSource }
val Provider<SourceSet>.compileClasspath: Provider<FileCollection>
get() = map { it.compileClasspath }
fun DependencyManagementExtension.deobf(dependency: Any, configure: Dependency.() -> Unit) = deobf(dependency, closureOf(configure))
fun Project.fileTree(dir: String, include: String) = fileTree("dir" to dir, "include" to include)
// endregion
// region project
group = modGroup
version = "${mcVersion}-${modVersion}"
base.archivesName.set(modId)
if (System.getenv("RELEASE_TYPE") != null) {
status = System.getenv("RELEASE_TYPE").lowercase()
if (status == "snapshot") status = (status as String).uppercase()
} else {
status = "SNAPSHOT"
}
if (status != "release") {
version = "${version}-${status}"
}
// endregion
mixin {
add(sourceSets.main.get(), "${modId}.refmap.json")
config("${modId}.mixins.json")
dumpTargetOnFailure = true
}
java {
withSourcesJar()
withJavadocJar()
toolchain {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
if (System.getenv("GITHUB_ACTIONS") == null || System.getenv("GITHUB_ACTIONS").isEmpty()) {
vendor.set(JvmVendorSpec.matching("JetBrains s.r.o."))
} else {
vendor.set(JvmVendorSpec.ADOPTIUM)
}
}
}
sourceSets {
main {
resources {
srcDir(file("src/main/generated"))
exclude(".cache")
}
}
}
repositories {
mavenLocal()
mavenCentral()
maven {
name = "Sponge maven"
url = uri("https://repo.spongepowered.org/repository/maven-public/")
content {
includeGroup("org.spongepowered")
}
}
}
dependencies {
minecraft("net.minecraftforge:forge:${mcVersion}-${forgeVersion}")
annotationProcessor("org.spongepowered:mixin:${mixinVersion}:processor")
compileOnly("org.jetbrains:annotations:23.0.0")
}
minecraft {
mappings(mappingsChannel, mappingsVersion)
copyIdeResources.set(true)
runs {
create("client") {
workingDirectory(file("run"))
property("forge.logging.console.level", "debug")
mods.register(modId) {
source(sourceSets.main.get())
}
}
create("server") {
workingDirectory(file("run"))
property("forge.logging.console.level", "debug")
mods.register(modId) {
source(sourceSets.main.get())
}
}
create("data") {
workingDirectory(file("run"))
property("forge.logging.console.level", "debug")
args("--mod", modId, "--all", "--output", file("src/main/generated/"), "--existing", file("src/main/resources/"))
mods.register(modId) {
source(sourceSets.main.get())
}
}
}
}
tasks {
withType<Jar>().configureEach {
manifest {
attributes(mapOf(
"Maven-Artifact" to "${modGroup}:${base.archivesName}:${project.version}",
"Specification-Title" to base.archivesName,
"Specification-Vendor" to vendor,
"Specification-Version" to "1",
"Implementation-Title" to base.archivesName,
"Implementation-Version" to modVersion,
"Implementation-Vendor" to vendor,
"Built-On-Java" to "${System.getProperty("java.vm.version")} (${System.getProperty("java.vm.vendor")})",
"Built-On" to "${mcVersion}-${forgeVersion}",
"Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()),
"FMLModType" to "MOD"
))
}
}
named<Jar>("jar") {
finalizedBy("reobfJar")
}
processResources {
val buildProps = project.properties.toMutableMap()
buildProps.values.removeIf { it !is CharSequence && it !is Number && it !is Boolean }
inputs.properties(buildProps)
filesMatching("META-INF/mods.toml") {
expand(buildProps)
}
// minify json files
doLast {
fileTree(dir = outputs.files.asPath, include = "**/*.json").forEach {
it.writeText(JsonOutput.toJson(JsonSlurper().parse(it)))
}
}
}
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
}
publishing {
publications.create<MavenPublication>("${base.archivesName.get()}ToMaven") {
groupId = project.group as String
artifactId = base.archivesName.get()
version = project.version as String
from(components["java"])
fg.component(this)
pom {
name.set(modName)
url.set("https://github.com/${githubRepo}")
packaging = "jar"
scm {
connection.set("scm:git:git://github.com/${githubRepo}.git")
developerConnection.set("scm:git:[email protected]:${githubRepo}.git")
url.set("https://github.com/${githubRepo}")
}
issueManagement {
system.set("github")
url.set(issueTrackerUrl)
}
organization {
name.set("Minecraftschurli Mods")
url.set("https://github.com/MinecraftschurliMods")
}
developers {
developer {
id.set("minecraftschurli")
name.set("Minecraftschurli")
url.set("https://github.com/Minecraftschurli")
email.set("[email protected]")
organization.set("Minecraftschurli Mods")
organizationUrl.set("https://github.com/MinecraftschurliMods")
timezone.set("Europe/Vienna")
}
}
}
}
repositories {
maven {
if ((System.getenv("MAVEN_USER") != null)
&& (System.getenv("MAVEN_PASSWORD") != null)
&& (System.getenv("MAVEN_URL") != null)) {
url = uri(System.getenv("MAVEN_URL"))
credentials {
username = System.getenv("MAVEN_USER")
password = System.getenv("MAVEN_PASSWORD")
}
} else {
url = uri("$buildDir/repo")
}
}
}
}