-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathbuild.gradle
More file actions
361 lines (303 loc) · 11.3 KB
/
build.gradle
File metadata and controls
361 lines (303 loc) · 11.3 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
plugins {
id 'groovy'
id 'net.fabricmc.fabric-loom' version "${loom_version}" apply false
id "com.hypherionmc.modutils.modpublisher" version "2.2.1"
}
build {
dependsOn ':ec-core:build'
}
ext.env = loadenv()
String getenv(String key) {
return ext.env.getOrDefault(key, "NOT FOUND")
}
tasks.named('jar').configure {
dependsOn(tasks.named('compileTestGroovy'))
}
allprojects {
apply plugin: 'net.fabricmc.fabric-loom'
apply plugin: 'maven-publish'
apply plugin: 'idea'
group = project.maven_group
String vers_suffix = getenv("VERSION_SUFFIX")
String full_version = vers_suffix != 'NOT FOUND' && vers_suffix != ''
? "${project.mod_version}-mc${project.minecraft_version}+${vers_suffix}"
: "${project.mod_version}-mc${project.minecraft_version}"
version = full_version
base.archivesName = "${project.mod_id}"
println "version: $full_version"
println "base.archivesName: ${base.archivesName.get()}"
repositories {
gradlePluginPortal()
mavenCentral()
// mavenLocal()
maven { name 'Fabric'; url 'https://maven.fabricmc.net/' }
maven { url 'https://maven.nucleoid.xyz' } // Used by FabricPlaceholderAPI
maven {
name = 'Ladysnake Mods'
url = 'https://maven.ladysnake.org/releases'
content {
includeGroup 'io.github.ladysnake'
includeGroupByRegex 'org\\.ladysnake.*'
}
}
maven {
name = 'jpcode'
url = 'https://maven.jpcode.dev/'
content {
includeGroup 'io.github.ladysnake'
includeGroupByRegex 'org\\.ladysnake.*'
}
}
maven { url "https://api.modrinth.com/maven" } // for vanish
}
loom {
splitEnvironmentSourceSets()
mods {
"${project.mod_id}" {
sourceSet sourceSets.main
}
}
}
// Common dependencies for all projects
dependencies {
// Fabric
minecraft "com.mojang:minecraft:${project.minecraft_version}"
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
implementation "eu.pb4:placeholder-api:${project.placeholder_api_version}"
// Code Quality
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
testImplementation platform("org.junit:junit-bom:${project.junit_bom_version}")
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
}
processResources {
inputs.property 'id', project.mod_id
inputs.property 'name', project.mod_name
inputs.property 'version', project.version
filesMatching('fabric.mod.json') {
expand([
'id': project.mod_id,
'name': project.mod_name,
'version': project.version
])
}
}
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
// java version
it.options.release.set(25)
}
test {
useJUnitPlatform()
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}
jar {
inputs.property "archivesName", project.base.archivesName
from("LICENSE") {
rename { "${it}_${inputs.properties.archivesName}"}
}
}
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.mod_id
groupId = project.maven_group
version = project.version
from components.java
}
}
// Add repositories to publish to
repositories {
mavenLocal { }
maven {
name 'GitHub'
url "https://maven.pkg.github.com/${project.gh_owner}/${project.gh_repo}"
credentials {
username = getenv('GITHUB_ACTOR')
password = getenv('GITHUB_TOKEN')
}
}
}
}
}
// Root-project-specific dependencies
dependencies {
implementation "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
// JIJ Dependencies (include for packaging)
implementation "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
include "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
include "eu.pb4:placeholder-api:${project.placeholder_api_version}"
implementation "org.yaml:snakeyaml:${project.snakeyaml_version}"
include "org.yaml:snakeyaml:${project.snakeyaml_version}"
implementation "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
include "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
// mod compatibility
compileOnly "maven.modrinth:vanish:${project.vanish_version}"
subprojects.each {
implementation project(path: ":${it.name}")
include project("${it.name}:")
}
}
// ModPublisher Configuration
publisher {
apiKeys {
modrinth getenv("MODRINTH")
curseforge getenv("CURSEFORGE")
github getenv("GITHUB")
}
setDebug(false)
setCurseID(project.cf_project_id)
setModrinthID(project.modrinth_project_id)
setVersionType(project.version.contains('alpha') ? 'alpha'
: project.version.contains('beta') ? 'beta'
: 'release')
setChangelog(readLatestChangelogSection())
setProjectVersion(project.version as String)
setDisplayName(project.version as String)
setGameVersions(project.game_versions.split(',').collect { it.trim() })
setLoaders("fabric")
setCurseEnvironment("both")
setArtifact(jar)
setJavaVersions([JavaVersion.VERSION_25])
// Add subproject artifacts as additional files
subprojects.each { subproject ->
addAdditionalFile(subproject.jar)
}
github {
repo("${project.gh_owner}/${project.gh_repo}")
tag(project.version as String)
target("1.21.x")
}
modrinthDepends {
if (project.hasProperty('mr_relations_required') && project.mr_relations_required?.trim()) {
project.mr_relations_required.split(',').each { dep ->
required dep.trim()
}
}
if (project.hasProperty('mr_relations_optional') && project.mr_relations_optional?.trim()) {
project.mr_relations_optional.split(',').each { dep ->
optional dep.trim()
}
}
if (project.hasProperty('mr_relations_embedded') && project.mr_relations_embedded?.trim()) {
project.mr_relations_embedded.split(',').each { dep ->
embedded dep.trim()
}
}
if (project.hasProperty('mr_relations_incompatible') && project.mr_relations_incompatible?.trim()) {
project.mr_relations_incompatible.split(',').each { dep ->
incompatible dep.trim()
}
}
}
curseDepends {
if (project.hasProperty('cf_relations_required') && project.cf_relations_required?.trim()) {
project.cf_relations_required.split(',').each { dep ->
required dep.trim()
}
}
if (project.hasProperty('cf_relations_optional') && project.cf_relations_optional?.trim()) {
project.cf_relations_optional.split(',').each { dep ->
optional dep.trim()
}
}
if (project.hasProperty('cf_relations_embedded') && project.cf_relations_embedded?.trim()) {
project.cf_relations_embedded.split(',').each { dep ->
embedded dep.trim()
}
}
if (project.hasProperty('cf_relations_incompatible') && project.cf_relations_incompatible?.trim()) {
project.cf_relations_incompatible.split(',').each { dep ->
incompatible dep.trim()
}
}
}
}
tasks.named('publishCurseforge').configure {
doFirst {
def key = getenv('CURSEFORGE')
if (key == 'NOT FOUND' || key.isEmpty()) {
throw new GradleException("CURSEFORGE API key is required for publishing to CurseForge")
}
}
}
tasks.named('publishModrinth').configure {
doFirst {
def key = getenv('MODRINTH')
if (key == 'NOT FOUND' || key.isEmpty()) {
throw new GradleException("MODRINTH API key is required for publishing to Modrinth")
}
}
}
tasks.named('publishGitHub').configure {
doFirst {
def key = getenv('GITHUB')
if (key == 'NOT FOUND' || key.isEmpty()) {
throw new GradleException("GITHUB API key is required for publishing to GitHub")
}
}
}
generatePomFileForMavenJavaPublication {}
def static loadenv(String path = ".env") {
def env = [:]
def file = new File(path)
if (file.exists()) {
file.eachLine { line ->
def (name, value) = line.tokenize("=")
env[name.trim()] = value.trim()
}
}
for (el in System.getenv()) {
env[el.key] = el.value
}
return env
}
ext.cachedChangelog = null
String readChangelogFromFile() {
if (ext.has('cachedChangelog')) {
return ext.cachedChangelog
}
String changelogFilePath = './changelog.md'
var file = new File(changelogFilePath)
if (!file.exists()) {
logger.warn("'%s' not found.", changelogFilePath)
ext.cachedChangelog = "changelog file not found"
return ext.cachedChangelog
}
ext.cachedChangelog = file.getText('UTF-8')
return ext.cachedChangelog
}
String readLatestChangelogSection() {
String fullChangelog = readChangelogFromFile()
if (fullChangelog == "changelog file not found") {
return fullChangelog
}
String[] sections = fullChangelog.split('--- --- ---')
String mostRecentSection = sections[0].trim()
var dashIdx = project.mod_version.indexOf('-')
var plusIdx = project.mod_version.indexOf('+')
var indexOfMainVersionEnd
= dashIdx != -1 && plusIdx != -1 ? Math.min(dashIdx, plusIdx)
: dashIdx != -1 ? dashIdx
: plusIdx != -1 ? plusIdx
: project.mod_version.length()
var mod_main_version = project.mod_version.substring(0, indexOfMainVersionEnd)
if (!mostRecentSection.contains("v$mod_main_version")) {
throw new RuntimeException("Changelog does not contain a section for the current version")
}
String suffix = """---
If you discover any bugs, you can report them in the [Issue Tracker](https://github.com/John-Paul-R/Essential-Commands/issues).
Additional conversation can be had in the [dev room discord](https://discord.jpcode.dev/essential-commands).
"""
return mostRecentSection + '\n\n' + suffix
}