-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
223 lines (205 loc) · 7.48 KB
/
build.gradle
File metadata and controls
223 lines (205 loc) · 7.48 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
/**
* BUILD WORKFLOW
*
* Main project:
* 1: Setup separate configurations for importing subproject classes & resources as depedencies
* 2: Avoid duplicates by only importing subprojects with unique classes or resources
* 3: Ensure the dependency graph is properly setup for the jar task
* 4: Use Shadow to relocate included API dependencies
* 5: Set up dependency graph for sourcesJar & javadocJar tasks
*
* Sub Projects:
* 1: Disable the local jar task unless it is necessary for remapping
* 2: Setup separate configurations for importing parent classes & resources as depedencies
* 3: Setup separate configurations for exporting classes & resources as artifacts
* 3: Collect all necessary classes & resources from parents to ensure the run tasks are functional
* 4: Use Shadow to duplicate shared classes for separate forge/fabric/neoforge mappings
* 5: Ensure classes are remapped before being exported to the main project for building
*/
/*
* External Plugin List
*
* - CurseGradle
* + [id] com.matthewprenger.cursegradle
* + [docs] https://github.com/matthewprenger/CurseGradle/wiki
* + [desc] Publish files to CurseForge
*
* - Gradle Doctor
* + [id] com.osacky.doctor
* + [docs] https://runningcode.github.io/gradle-doctor/
* + [desc] Helps to diagnose build performance issues & can only be applied in the root project
*
* - Mod Publish
* + [id] me.modmuss50.mod-publish-plugin
* + [docs] https://modmuss50.github.io/mod-publish-plugin/
* + [desc] A modern Gradle plugin to publish mods to a range of destinations
*
* - Shadow
* + [id] com.gradleup.shadow
* + [docs] https://gradleup.com/shadow/
* + [desc] FatJar builder & package relocator
*
* - Unimined
* + [id] unimined
* + [docs] https://github.com/unimined/Unimined/blob/main/Writerside/topics/starter-topic.md
* + [desc] Minecraft provider & remapper
*
* - Wiki Dev Toolkit
* + [id] org.moddedmc.wiki.toolkit
* + [docs] https://docs.moddedmc.wiki/docs/tools/gradle
* + [desc] Publish docs to the Modded Minecraft Wiki
*/
plugins {
alias libs.plugins.doctor
alias libs.plugins.mod.publish
alias libs.plugins.wiki
id 'shaded-deps'
}
addParentProcessedResources()
createClassesImport 'apiClasses', 'gatherAllClasses', 'classes', 'main'
createConfiguration 'processedClasses', false, true
dependencies {
apiClasses project(path: ':api', configuration: 'exportClasses')
}
shadowJar {
configurations = [ 'apiClasses', 'processedClasses', 'shadow' ].collect {c_name ->
project.configurations.named(c_name).get()
}
dependsOn 'classes'
}
[ '1.12', 'shared_1.16', 'shared_1.18', 'shared_1.19.2', 'shared_1.19.4', 'shared_1.20.1', 'shared_1.20.4',
'shared_1.20.6', 'shared_1.21.1' ].forEach {included_project ->
String p_path = getFullPath included_project
dependencies {
processedClasses project(path: p_path, configuration: 'processedClasses')
}
shadowJar.dependsOn "$p_path:${'1.12'==included_project ? 'remap' : 'combined'}ClassesJar"
}
tasks.register('fixManifest', Jar) {
dependsOn shadowJar
archiveBaseName = mod_id
archiveClassifier = ''
doFirst {
from zipTree(tasks.named('shadowJar', Jar).get().archiveFile.get())
manifest {
attributes([
'FMLCorePlugin': legacy_entrypoint,
'FMLCorePluginContainsFMLMod': true,
'ForceLoadAsMod': true,
'Implementation-Title': mod_name,
'Implementation-Version': mod_version,
'TILMultiversionCoreMods': core_entrypoint,
'TILMultiversionMods': common_entrypoint
])
}
}
}
tasks.assemble.dependsOn fixManifest
tasks.gatherAllClasses.dependsOn ':api:classes'
tasks.publishMods.dependsOn assemble
tasks.shadowJar.finalizedBy fixManifest
//noinspection GrUnresolvedAccess
applySourceHelpers()
makeChangelogFile()
def debug_publish = false
publishMods {
//noinspection GrUnresolvedAccess
additionalFiles.from javadocJar.archiveFile, sourcesJar.archiveFile
changelog = readChangelog()
displayName = mod_name
dryRun = debug_publish
file = tasks.fixManifest.archiveFile
group = 'publishing'
//noinspection GrUnresolvedAccess
modLoaders.addAll readModLoaders()
type = ALPHA
version = mod_version
//noinspection GroovyAssignabilityCheck
curseforge {
accessToken = curseforge_token
announcementTitle = 'CurseForge'
clientRequired = true
//noinspection GrUnresolvedAccess
minecraftVersions.addAll readVersions()
projectId = curseforge_project_id
projectSlug = curseforge_project_slug
serverRequired = true
}
//noinspection GroovyAssignabilityCheck
modrinth {
accessToken = modrinth_token
announcementTitle = 'Modrinth'
//noinspection GrUnresolvedAccess
minecraftVersions.addAll readVersions()
projectId = modrinth_project_id
}
//noinspection GroovyAssignabilityCheck
discord {
dryRunWebhookUrl = webhook_modding_dev
username = 'Mod Updates'
webhookUrl = webhook_modding_announcements
//noinspection GrUnresolvedAccess
content = changelog.map {String changelog_txt ->
discordAnnoncementText changelog_txt
}
//noinspection GrUnresolvedAccess
style {
color = "#$webhook_color"
look = webhook_style
thumbnailUrl = logo_url
}
}
}
wiki {
wikiAccessToken = wiki_token.toString()
docs {
theimpossiblelibrary {
//noinspection GroovyAssignabilityCheck
root = file "docs/$mod_id"
}
}
}
tasks.register('publishAndSyncDocs') {
description = 'Publish all jar files and update all wiki files'
group = 'publishing'
dependsOn publishMods
dependsOn revalidateDocs
notCompatibleWithConfigurationCache 'Do not cache publishing tasks'
}
def discordAnnoncementText(String changelog) {//TODO Turn this into a template somewhere
return "<@&$til_role_id> We do a bit of automation\n"+
"\n" +
"## $mod_name has been updated to `$mod_version` <$til_emote_id>\n"+
"$changelog\n"+
"\n"+
"This is prety neat, isn't it? Anyways, hopefully there aren't any more issues specific to 1.20.1 now"
}
def makeChangelogFile() {
def changelogFile = file "changelogs/${mod_version}.txt"
if(!changelogFile.exists()) {
def parent = changelogFile.parentFile
if(!parent.exists()) parent.mkdirs()
if(changelogFile.createNewFile()) {
changelogFile.write '- WIP'
logger.info "Created changelog file for new version at ${changelogFile.absolutePath}"
} else logger.error "Failed to create changelog file for new version at ${changelogFile.absolutePath}"
}
}
String readChangelog() {
def changelogFile = file "changelogs/${mod_version}.txt"
try {
def lines = changelogFile.readLines()
def builder = new StringBuilder()
for(def line : lines) builder.append(line).append '\n'
return builder.toString()
} catch(Exception ex) {
getLogger().error "Failed to read lines from $changelogFile", ex
}
return ""
}
List<String> readModLoaders() {
return List.of(supported_modloaders.split(';'))
}
List<String> readVersions() {
return List.of(supported_versions.split(';'))
}