-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
245 lines (206 loc) · 8.09 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
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
import net.darkhax.curseforgegradle.TaskPublishCurseForge
import org.w3c.dom.Document
import org.w3c.dom.NodeList
import javax.xml.parsers.DocumentBuilderFactory
import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
plugins {
id 'java-library'
id 'idea'
id 'maven-publish'
id 'net.darkhax.curseforgegradle' version '1.1.18'
id 'com.modrinth.minotaur' version '2.+'
id 'net.neoforged.moddev' version '[2.0,2.1)'
}
version = getVersion(minecraft_version + "-" + base_version, new URL(remote_maven + "/" + group.replace('.', '/') + "/" + name + "/maven-metadata.xml"))
repositories {
mavenLocal()
}
base {
archivesName = project.name
}
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
configurations {
runtimeClasspath.extendsFrom localRuntime
}
neoForge {
version = project.neo_version
validateAccessTransformers = true
parchment {
minecraftVersion = project.parchment_minecraft_version
mappingsVersion = project.parchment_mappings_version
}
runs {
client {
client()
systemProperty 'neoforge.enableGameTestNamespaces', project.modid
}
server {
server()
programArgument '--nogui'
systemProperty 'neoforge.enabledGameTestNamespaces', project.modid
}
data {
data()
programArguments.addAll '--mod', project.modid, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.modid
}
configureEach {
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
systemProperty 'forge.logging.markers', 'REGISTRIES'
logLevel = org.slf4j.event.Level.DEBUG
gameDirectory = project.file('run' + name.capitalize())
}
}
mods {
// define mod <-> source bindings
// these are used to tell the game which sources are for which mod
// mostly optional in a single mod project
// but multi mod projects should define one per mod
"${modid}" {
sourceSet(sourceSets.main)
}
}
}
tasks.withType(ProcessResources).configureEach {
var replaceProperties = [
minecraft_version : minecraft_version,
neo_version : neo_version,
loader_version_range: loader_version_range,
modid : modid,
license : license,
mod_version : version
]
inputs.properties replaceProperties
filesMatching(['META-INF/neoforge.mods.toml']) {
expand replaceProperties
}
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = project.group
artifactId = project.name
version = project.version
artifact(jar)
pom {
licenses {
license {
name = license
url = license_url
}
}
}
}
}
repositories {
maven {
url "https://maven.melanx.de/release"
credentials {
username = project.findProperty('mavenUsername') ?: System.getenv('MAVEN_USERNAME')
password = project.findProperty('mavenPassword') ?: System.getenv('MAVEN_PASSWORD')
}
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
private static String getVersion(String baseVersion, URL url) {
try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection()
connection.setRequestMethod("GET")
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(connection.getInputStream())
NodeList versionNodes = doc.getElementsByTagName("version")
String latestVersion = null;
for (int i = 0; i < versionNodes.getLength(); i++) {
String version = versionNodes.item(i).getTextContent()
if (version.startsWith(baseVersion)) {
latestVersion = version
}
}
if (latestVersion == null) {
return baseVersion + ".0"
}
return baseVersion + "." + (Integer.parseInt(latestVersion.substring(latestVersion.lastIndexOf('.') + 1)) + 1)
} catch (FileNotFoundException ignored) {
// This exception is thrown if the maven-metadata.xml file doesn't exist at the provided URL,
// which would be the case if there were no previous publications to this Maven repository with this project
return baseVersion + ".0"
} catch (Exception e) {
throw new RuntimeException(e)
}
}
if (!getProperty('project', 'curse').isEmpty()) {
task curseforge(type: TaskPublishCurseForge) {
apiToken = project.findProperty('curse_token') ?: System.getenv('CURSEFORGE_TOKEN') ?: ''
Closure fileConfig = { file ->
file.releaseType = getProperty('release', 'curse', 'release')
file.changelog = changelog(project)
file.changelogType = 'markdown'
getArray(getProperty('requirements', 'curse')).each { file.addRequirement(it) }
getArray(getProperty('optionals', 'curse')).each { file.addOptional(it) }
getArray(getProperty('versions', 'curse', minecraft_version)).each { file.addGameVersion(it) }
file.addModLoader('neoforge')
}
def mainFile = upload(getProperty('project', 'curse'), jar)
fileConfig(mainFile)
}
project.tasks.getByName('curseforge').dependsOn('build')
}
if (!getProperty('project', 'modrinth').isEmpty()) {
modrinth {
token = project.findProperty('modrinth_token') ?: System.getenv('MODRINTH_TOKEN') ?: ''
projectId = getProperty('project', 'modrinth')
versionNumber = project.version
versionName = jar.getArchiveFileName().get()
uploadFile = jar
dependencies = []
changelog = changelog(project)
versionType = getProperty('release', 'modrinth', 'release')
getArray(getProperty('requirements', 'modrinth')).each { dependencies.add(new com.modrinth.minotaur.dependencies.ModDependency(it, 'required')) }
getArray(getProperty('optionals', 'modrinth')).each { dependencies.add(new com.modrinth.minotaur.dependencies.ModDependency(it, 'optional')) }
gameVersions = getArray(getProperty('versions', 'modrinth', minecraft_version)).toList()
loaders = ['neoforge']
}
}
String getProperty(String entry, String platform) {
return getProperty(entry, platform, '')
}
String getProperty(String entry, String platform, String ret) {
return project.findProperty('upload_' + entry) ?: project.findProperty(platform + '_' + entry) ?: ret
}
static String[] getArray(String deps) {
return deps.split(',')*.strip().toList().findAll { !it.isEmpty() }
}
String changelog(Project project) {
String logFmt = '--pretty=tformat:"- [%s](' + project.changelog_repository.toString() + ') - *%aN*"'
def stdout = new ByteArrayOutputStream()
def gitHash = System.getenv('GIT_COMMIT')
def gitPrevHash = System.getenv('GIT_PREVIOUS_COMMIT')
if (gitPrevHash == "0000000000000000000000000000000000000000") {
gitPrevHash = "HEAD~1"
}
if (gitHash != null && gitPrevHash != null) {
exec {
commandLine 'bash', '-c', "git log ${logFmt} ${gitPrevHash}...${gitHash} | grep -v '^- \\[\\[meta\\]'"
standardOutput = stdout
}
} else {
stdout.write('No changelog provided\n'.getBytes(StandardCharsets.UTF_8))
}
return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(stdout.toByteArray())).toString()
}