forked from TerminalMC/CommandKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
165 lines (152 loc) · 7.5 KB
/
build.gradle
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
plugins {
id("fabric-loom") version("${loom_version}") apply(false)
id("net.neoforged.moddev") version("${moddev_version}") apply(false)
id("com.modrinth.minotaur") version("${minotaur_version}")
id("net.darkhax.curseforgegradle") version("${curseforgegradle_version}")
id("com.github.breadmoirai.github-release") version("${githubrelease_version}")
id("org.ajoberstar.grgit.service") version("${grgitservice_version}")
id("org.cadixdev.licenser") version("${licenser_version}")
}
subprojects {
version = mod_version
group = mod_group
if (name == "common") {
// License headers
apply(plugin: "org.cadixdev.licenser")
String licenseDir = "src/main/resources/assets/${mod_id}/license/"
license {
// This can be done in multiloader-common.gradle but only if the
// "matching" method is not used (throws a pile of weird errors).
// Also, NeoForge's update of the plugin can't handle matching at all.
include("**/*.java") // Java files only
header = project.file(licenseDir + "HEADER.txt")
properties {
project_name = mod_name
owner_name = mod_owner
year = java.time.LocalDate.now().getYear().toString()
}
}
} else {
// Publishing
apply(plugin: "com.modrinth.minotaur")
apply(plugin: "net.darkhax.curseforgegradle")
apply(plugin: "com.github.breadmoirai.github-release")
apply(plugin: "org.ajoberstar.grgit.service")
afterEvaluate {
modrinth {
token = System.getenv().MODRINTH_TOKEN ? System.getenv().MODRINTH_TOKEN : "empty"
projectId = modrinth_id
versionNumber = mod_version
versionType = release_type
versionName = "v${mod_version}-${capsLoader(name)}"
changelog = versionChangelog()
uploadFile = name == "fabric" ? remapJar : jar
loaders = project.property("release_mod_loaders_${name}").split(",") as List
gameVersions = project.property("release_game_versions_${name}").split(",") as List
def deps = []
if (project.hasProperty("release_required_dep_ids_${name}_mr")) {
project.property("release_required_dep_ids_${name}_mr").split(",").each { String id ->
deps << new com.modrinth.minotaur.dependencies.ModDependency(id, "required")
}
}
if (project.hasProperty("release_optional_dep_ids_${name}_mr")) {
project.property("release_optional_dep_ids_${name}_mr").split(",").each { String id ->
deps << new com.modrinth.minotaur.dependencies.ModDependency(id, "optional")
}
}
if (project.hasProperty("release_incompatible_dep_ids_${name}_mr")) {
project.property("release_incompatible_dep_ids_${name}_mr").split(",").each { String id ->
deps << new com.modrinth.minotaur.dependencies.ModDependency(id, "incompatible")
}
}
dependencies = deps
syncBodyFrom = rootProject.file("README.md").text
}
tasks.modrinth.onlyIf { System.getenv().MODRINTH_TOKEN }
tasks.modrinth.dependsOn(build, tasks.modrinthSyncBody)
tasks.modrinthSyncBody.onlyIf { System.getenv().MODRINTH_TOKEN }
task curseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
apiToken = System.getenv().CURSEFORGE_TOKEN ? System.getenv().CURSEFORGE_TOKEN : "empty"
disableVersionDetection()
String module = project.name
def file = upload(curseforge_id, module == "fabric" ? remapJar : jar)
file.displayName = "v${mod_version}-${capsLoader(module)}"
file.releaseType = release_type
file.changelog = versionChangelog()
file.changelogType = "markdown"
project.property("release_mod_loaders_${module}").split(",").each { String id ->
file.addModLoader(id)
}
project.property("release_game_versions_${module}").split(",").each { String id ->
file.addGameVersion(id, module)
}
if (project.hasProperty("release_required_dep_ids_${module}_cf")) {
project.property("release_required_dep_ids_${module}_cf").split(",").each { String id ->
file.addRequirement(id)
}
}
if (project.hasProperty("release_optional_dep_ids_${module}_cf")) {
project.property("release_optional_dep_ids_${module}_cf").split(",").each { String id ->
file.addOptional(id)
}
}
if (project.hasProperty("release_incompatible_dep_ids_${module}_cf")) {
project.property("release_incompatible_dep_ids_${module}_cf").split(",").each { String id ->
file.addIncompatibility(id)
}
}
}
tasks.curseforge.onlyIf { System.getenv().CURSEFORGE_TOKEN }
tasks.curseforge.dependsOn(build)
githubRelease {
token = System.getenv().GITHUB_TOKEN ? System.getenv().GITHUB_TOKEN : "empty"
owner = github_repo_owner
repo = github_repo
tagName = "v${mod_version}"
prerelease = release_type == "alpha" || release_type == "beta"
releaseName = "v${mod_version}"
String changelog = "\n\n## Changelog\n\n" + versionChangelog()
String versions = "## MC versions\n\n"
if (project.hasProperty("release_game_versions_fabric"))
versions = String.format("%s - Fabric: %s\n", versions,
project.property("release_game_versions_fabric"))
if (project.hasProperty("release_game_versions_neoforge"))
versions = String.format("%s - NeoForge: %s\n", versions,
project.property("release_game_versions_neoforge"))
body = versions + changelog
targetCommitish = grgitService.service.get().grgit.branch.current().name
overwrite = false
allowUploadToExisting = true
releaseAssets = List.of(name == "fabric" ? remapJar : jar, sourcesJar)
}
tasks.githubRelease.onlyIf { System.getenv().GITHUB_TOKEN }
tasks.githubRelease.dependsOn(build)
}
}
}
String versionChangelog() {
List<String> lines = rootProject.file("CHANGELOG.md").readLines()
StringBuilder builder = new StringBuilder()
for (int i = 4; i < lines.size(); i++) {
String line = lines.get(i)
if (line.isBlank()) {
// pass
} else if (line.startsWith("## ")) {
break
}
else {
if (!builder.isEmpty()) builder.append("\n")
builder.append(line)
}
}
return builder.toString()
}
static String capsLoader(String loader) {
switch(loader) {
case "fabric": return "Fabric"
case "quilt": return "Quilt"
case "forge": return "Forge"
case "neoforge": return "NeoForge"
default: return loader
}
}