-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.gradle
More file actions
213 lines (205 loc) · 9.44 KB
/
build.gradle
File metadata and controls
213 lines (205 loc) · 9.44 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
import me.modmuss50.mpp.ReleaseType
import util.EnvUtil
import util.PropUtil
import util.StaticUtil
import java.time.LocalDate
plugins {
id("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 {
final env = new EnvUtil(providers)
final prop = new PropUtil(project)
final cLog = StaticUtil.versionChangelog(rootProject.file("changelog.md"), mod_version)
// Append Minecraft version extension
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 dep_abbrev = data[0]
// Strip meta from dependency version
final dep_ver = prop.get(data[1]).split("\\+")[0]
mod_version = "${mod_version}+${dep_abbrev}${dep_ver}"
}
version = mod_version
group = mod_group
// Configure license headers
apply(plugin: "net.neoforged.licenser")
final licenseDir = "src/main/resources/assets/${mod_id}/license/"
license {
include("**/*.java") // Java files only
// 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
}
}
}
}
// Configure multi-site publishing
if (name != "common") {
apply(plugin: "me.modmuss50.mod-publish-plugin")
apply(plugin: "org.ajoberstar.grgit.service")
afterEvaluate { sp ->
publishMods {
// Common configuration
file = sp.name == "fabric" ? remapJar.archiveFile : jar.archiveFile
version = mod_version
type = ReleaseType.of(mod_version_type)
displayName = "v${mod_version}-${StaticUtil.capsLoader(sp.name)}"
modLoaders.addAll(prop.safeList("mod_loaders_${sp.name}"))
maxRetries = 5
dryRun = !env.has("GITHUB_TOKEN")
&& !env.has("MODRINTH_TOKEN")
&& !env.has("CURSEFORGE_TOKEN")
// GitHub configuration
github {
parent project(":").tasks.named("publishGithub")
accessToken = env.safe("GITHUB_TOKEN")
if (build_sources_jar == "true") additionalFiles.from(sourcesJar.archiveFile)
if (build_javadoc_jar == "true") additionalFiles.from(javadocJar.archiveFile)
return void
}
// Modrinth configuration
modrinth {
accessToken = env.safe("MODRINTH_TOKEN")
projectId = prop.safe("mod_modrinth_id")
minecraftVersions.addAll(prop.safeList("mc_versions_${sp.name}"))
changelog = cLog
prop.safeList("${sp.name}_deps").each { dep ->
try {
final depData = prop.list("d_${sp.name}_${dep}")
if (depData.length > 2 && depData[2] != "-") {
final mrDepData = depData[2].split(":")
final 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 '${sp.name}'. Check dependency property format.")
throw ex
}
}
// Sync Modrinth description with README
if (prop.has("mod_github_repo")) {
projectDescription = rootProject.file("README.md").text.replaceAll(
"src=\"\\./",
"src=\"https://raw.githubusercontent.com/${prop.get("mod_github_repo")}/HEAD/"
)
return
}
}
// CurseForge configuration
curseforge {
accessToken = env.safe("CURSEFORGE_TOKEN")
projectId = prop.safe("mod_curseforge_id")
projectSlug = prop.safe("mod_curseforge_slug")
minecraftVersions.addAll(prop.safeList("mc_versions_${sp.name}"))
changelog = cLog
prop.safeList("${sp.name}_deps").each { dep ->
try {
final depData = prop.list("d_${sp.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 '${sp.name}'. Check dependency property format.")
throw ex
}
}
return void
}
}
final hasSpConf = prop.has("mod_loaders_${name}") && prop.has("mc_versions_${name}")
tasks.named("publishGithub") {
onlyIf {
return hasSpConf
&& prop.has("mod_github_repo")
&& (it["dryRun"].get() || env.has("GITHUB_TOKEN"))
}
}
tasks.named("publishModrinth") {
onlyIf {
return hasSpConf
&& prop.has("mod_modrinth_id")
&& (it["dryRun"].get() || env.has("MODRINTH_TOKEN"))
}
}
tasks.named("publishCurseforge") {
onlyIf {
return hasSpConf
&& prop.has("mod_curseforge_id")
&& prop.has("mod_curseforge_slug")
&& (it["dryRun"].get() || env.has("CURSEFORGE_TOKEN"))
}
}
}
}
}
/*
This configuration, combined with the subproject configuration above, allows
multiple files to be uploaded to a single GitHub release.
*/
publishMods {
final env = new EnvUtil(providers)
final prop = new PropUtil(project)
version = "${mod_version}+${minecraft_version}"
displayName = "v${mod_version}+${minecraft_version}"
type = ReleaseType.of(mod_version_type)
dryRun = !env.has("GITHUB_TOKEN")
github {
accessToken = env.safe("GITHUB_TOKEN")
repository = prop.safe("mod_github_repo")
commitish = grgitService.service.get().grgit.branch.current().name
tagName = "v${mod_version}+${minecraft_version}"
allowEmptyFiles = true
// Link to header in changelog file
changelog = "[Changelog](./changelog.md#${mod_version.replaceAll("\\.", "")})"
}
tasks.named("publishGithub") {
onlyIf {
return prop.has("mod_github_repo")
&& (it["dryRun"].get() || env.has("GITHUB_TOKEN"))
}
}
}