-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
228 lines (213 loc) · 9.92 KB
/
Copy pathbuild.gradle
File metadata and controls
228 lines (213 loc) · 9.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
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
import me.modmuss50.mpp.ReleaseType
import util.EnvUtil
import util.PropUtil
import util.StaticUtil
import java.nio.charset.StandardCharsets
import java.time.LocalDate
import java.time.format.DateTimeFormatter
plugins {
id("net.fabricmc.fabric-loom") version("${loom_version}") apply(false)
id("net.neoforged.moddev") version("${moddev_version}") apply(false)
id("net.neoforged.licenser") version("${licenser_version}") apply(false)
id("me.modmuss50.mod-publish-plugin") version("${mpp_version}")
id("org.ajoberstar.grgit.service") version("${grgitservice_version}")
}
subprojects { Project $subproject ->
final EnvUtil $env = new EnvUtil(providers)
final PropUtil $prop = new PropUtil(project)
// append Minecraft version extension
String $mod_version = "${mod_version}+${minecraft_version}"
// append dependency version extension, if configured
if ($prop.has("dep_ext_${name}")) {
final $data = $prop.get("dep_ext_${name}").split(":")
final $depAbbrev = $data[0]
// Strip meta from dependency version
final $depVer = $prop.get($data[1]).split("\\+")[0]
$mod_version = "${$mod_version}+${$depAbbrev}${$depVer}"
}
$subproject.version = $mod_version
$subproject.group = mod_group
// configure license headers
apply(plugin: "net.neoforged.licenser")
final String $licenseDir = "src/main/resources/assets/${mod_id}/license/"
license {
include("**/*.java")
// apply main license header
header = rootProject.project("common").file("${$licenseDir}HEADER.txt")
properties {
project_name = mod_name
owner_name = mod_owner
year = LocalDate.now().getYear().toString()
}
// apply attribution license headers, if configured
if (att_license_mods != "") {
att_license_mods.split(",").each { String $modId ->
//noinspection GroovyAssignabilityCheck
matching({ include($prop.list("att_license_files_${$modId}")) }) {
header = rootProject.project("common").file("${$licenseDir}${$modId}/HEADER.txt")
it
}
}
}
}
if ($subproject.name == "common")
return
// configure multi-site publishing
apply(plugin: "me.modmuss50.mod-publish-plugin")
apply(plugin: "org.ajoberstar.grgit.service")
afterEvaluate {
final StaticUtil.Changelog $changelog = StaticUtil.versionChangelog(
rootProject.file("CHANGELOG.md"),
mod_version
)
final String $date = LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)
publishMods {
// common configuration
file = jar.archiveFile
version = $mod_version
type = ReleaseType.valueOf(mod_version_type)
displayName = "v${$mod_version}-${StaticUtil.capsLoader($subproject.name)}"
modLoaders.addAll($prop.safeList("mod_loaders_${$subproject.name}"))
maxRetries = 5
dryRun = !$env.has("GITHUB_TOKEN")
&& !$env.has("MODRINTH_TOKEN")
&& !$env.has("CURSEFORGE_TOKEN")
// GitHub configuration
//noinspection GroovyAssignabilityCheck
github {
final String $urlHeader = URLEncoder.encode(
"${mod_version}-[${$date}]".replaceAll("\\.", ""),
StandardCharsets.UTF_8
)
accessToken = $env.safe("GITHUB_TOKEN")
repository = $prop.safe("mod_github_repo")
commitish = grgitService.service.get().grgit.branch.current().name
tagName = "v${$mod_version}-${$subproject.name}"
changelog = "[Changelog](./CHANGELOG.md#${$urlHeader})"
if (build_sources_jar == "true")
additionalFiles.from(provider { sourcesJar.archiveFile })
if (build_javadoc_jar == "true")
additionalFiles.from(provider { javadocJar.archiveFile })
}
// Modrinth configuration
//noinspection GroovyAssignabilityCheck
modrinth {
accessToken = $env.safe("MODRINTH_TOKEN")
projectId = $prop.safe("mod_modrinth_id")
minecraftVersions.addAll($prop.safeList("mc_versions_${$subproject.name}"))
changelog = $changelog.changelist
$prop.safeList("${$subproject.name}_deps").each { $dep ->
try {
final String[] $depData = $prop.list("d_${$subproject.name}_${$dep}")
if ($depData.length > 2 && $depData[2] != "-") {
final String[] $mrDepData = $depData[2].split(":")
final String $type = $mrDepData[0]
if ($type == "req") {
requires { id = $mrDepData[1] }
} else if ($type == "opt") {
optional { id = $mrDepData[1] }
} else if ($type == "inc") {
incompatible { id = $mrDepData[1] }
} else if ($type == "emb") {
embeds { id = $mrDepData[1] }
} else {
throw new IllegalArgumentException("Unrecognized dependency type: ${$mrDepData[0]}")
}
}
} catch (Exception ex) {
logger.error("Error processing Modrinth dependency '${$dep}' for "
+ "subproject '${$subproject.name}'. Check dependency property format.")
throw ex
}
}
// sync Modrinth description with README
if ($prop.has("mod_github_repo") && $env.safe("SYNC_DESC_MODRINTH") == "true") {
projectDescription = rootProject.file("README.md").text.replaceAll(
"src=\"\\./",
"src=\"https://raw.githubusercontent.com/${$prop.get("mod_github_repo")}/HEAD/"
)
return
}
}
// CurseForge configuration
//noinspection GroovyAssignabilityCheck
curseforge {
final String $cfEnvs = $prop.list("curseforge_environments")
if (!$cfEnvs.contains("client") && !$cfEnvs.contains("server")) {
throw new Exception("Property [curseforge_environments] must contain at least one of [client, server]")
}
accessToken = $env.safe("CURSEFORGE_TOKEN")
projectId = $prop.safe("mod_curseforge_id")
minecraftVersions.addAll($prop.safeList("mc_versions_${$subproject.name}").findAll {
!it.contains("-")
})
client = $cfEnvs.contains("client")
server = $cfEnvs.contains("server")
changelog = $changelog.changelist
$prop.safeList("${$subproject.name}_deps").each { $dep ->
try {
final $depData = $prop.list("d_${$subproject.name}_${$dep}")
if ($depData.length > 3 && $depData[3] != "-") {
final $cfDepData = $depData[3].split(":")
final $type = $cfDepData[0]
if ($type == "req") {
requires($cfDepData[1])
} else if ($type == "opt") {
optional($cfDepData[1])
} else if ($type == "inc") {
incompatible($cfDepData[1])
} else if ($type == "emb") {
embeds($cfDepData[1])
} else {
throw new IllegalArgumentException(
"Unrecognized dependency type: ${$cfDepData[0]}"
)
}
}
} catch (Exception ex) {
logger.error("Error processing CurseForge dependency '${$dep}' for "
+ "subproject '${$subproject.name}'. Check dependency property format.")
throw ex
}
}
return void
}
}
// execution conditions
final boolean $hasReleaseProps = $prop.has("mod_loaders_${$subproject.name}")
&& $prop.has("mc_versions_${$subproject.name}")
tasks.named("publishGithub") { Task $task ->
onlyIf {
return $hasReleaseProps && ($task["dryRun"].get() || $env.has("GITHUB_TOKEN"))
}
doFirst {
StaticUtil.validateChangelogDate($changelog.date)
}
}
tasks.named("publishModrinth") { Task $task ->
onlyIf {
return $hasReleaseProps && ($task["dryRun"].get() || $env.has("MODRINTH_TOKEN"))
}
doFirst {
StaticUtil.validateChangelogDate($changelog.date)
}
}
tasks.named("publishCurseforge") { Task $task ->
onlyIf {
return $hasReleaseProps && ($task["dryRun"].get() || $env.has("CURSEFORGE_TOKEN"))
&& $prop.safeList("mc_versions_${$subproject.name}").any { !it.contains("-") }
}
doFirst {
StaticUtil.validateChangelogDate($changelog.date)
}
}
}
}
// apply from other .gradle files
file(".").eachFile {
if (it.isFile() && it.name.endsWith(".gradle")
&& it.name != "build.gradle"
&& it.name != "settings.gradle") {
apply(from: it.name)
}
}