-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
257 lines (217 loc) · 8.32 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
246
247
248
249
250
251
252
253
254
255
256
257
import com.modrinth.minotaur.dependencies.ModDependency
plugins {
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
// 用于模组发布
id "com.modrinth.minotaur" version "2.+"
id 'net.darkhax.curseforgegradle' version '1.1.+'
id "com.github.breadmoirai.github-release" version "2.5.2"
}
base {
archivesName = project.archives_base_name + "-fabric"
}
version = project.mod_version + '-mc' + project.minecraft_version
group = project.maven_group
allprojects {
apply plugin: 'fabric-loom'
apply plugin: 'maven-publish'
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
// Mod Menu 模组
maven { url 'https://maven.terraformersmc.com/releases/' }
// Cloth Config、Roughly Enough Items
maven { url "https://maven.shedaniel.me/" }
// 合理模组(仅限 1.19.2 之前)。这两个模组均存储于本地的 maven 仓库。
mavenLocal()
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}")
// ModMenu 模组
modImplementation ("com.terraformersmc:modmenu:${project.modmenu_version}")
// 下面两个模组均存储于本地的 maven 仓库。
// 由于新版的 Loom 没有 @CanIgnoreReturnValue 等注解,故在这里手动添加。
modImplementation "com.google.errorprone:error_prone_annotations:+"
}
processResources {
inputs.property "version", project.mod_version
filesMatching("fabric.mod.json") {
expand "version": project.mod_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"
it.options.release = 21
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}" }
}
}
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
loom {
runs {
client {
programArg "-username=Solid"
}
}
runConfigs.configureEach {
it.configName = "Minecraft Fabric ${it.name.capitalize()}"
ideConfigGenerated = true
runDir = project.relativePath(project(':').file('run')).toString()
}
}
}
ext {
release_type = mod_version.contains('alpha') ? 'alpha' : mod_version.contains('beta') ? 'beta' : 'release' as String
}
subprojects {
dependencies {
}
}
project(':runtest') {
repositories {
// Mods on CurseForge
maven {
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
}
dependencies {
implementation project(path: ':', configuration: "namedElements")
implementation project(path: ':with_blockus', configuration: "namedElements")
if (project.hasProperty('imblocker_version') && !project.imblocker_version.isEmpty()) {
modRuntimeOnly "curse.maven:imblockerfabric-399225:$project.imblocker_version"
}
if (project.hasProperty('rei_version') && !project.rei_version.isEmpty()) {
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:$project.rei_version"
}
}
[tasks.remapJar, tasks.remapSourcesJar, tasks.build].each {
it.enabled = false
}
}
/**
* 从 UpdateLog-en.md 中提取更新日志
*/
String getUpdateLog(String modVersion = project.mod_version) {
StringBuilder builder = new StringBuilder()
boolean start = false
file('UpdateLog-en.md').eachLine {
if (it.matches("^###\\s*" + modVersion + '$')) {
start = true
} else if (it.startsWith("###")) {
start = false
} else if (start) {
builder.append it
builder.append '\n'
}
return
}
return builder.toString().trim()
}
// 模组发布部分
println "当前版本(${project.mod_version})更新记录:"
final String changelogContent = getUpdateLog(project.mod_version.replaceAll('-.+?\$', ""))
println changelogContent
tasks.register('curseforge', net.darkhax.curseforgegradle.TaskPublishCurseForge) {
doFirst {
def getenv = System.getenv("CURSEFORGE_TOKEN")
println("CurseForge 令牌: $getenv")
if (getenv) apiToken = getenv
}
def mainFile = upload('514125', remapJar)
mainFile.changelog = changelogContent
mainFile.changelogType = 'markdown'
mainFile.releaseType = release_type
for (final String v in (project.supported_minecraft_versions.split(','))) {
mainFile.addGameVersion v
}
mainFile.addRelations 'requiredDependency', 'fabric-api'
// The sources JAR
def sourcesFile = mainFile.withAdditionalFile(sourcesJar)
}
modrinth {
projectId = 'tb7kCxSW'
String platform = project.properties.getOrDefault 'loom.platform', 'fabric'
versionNumber = "${rootProject.mod_version}-${platform}-${rootProject.minecraft_version}"
versionType = release_type
uploadFile = remapJar
gameVersions = project.supported_minecraft_versions.isEmpty() ? List.of(rootProject.minecraft_version) : (project.supported_minecraft_versions as String).split(',') as List<String>
loaders = [platform]
var dependenciesList = []
if (platform == 'fabric') dependenciesList.add new ModDependency('P7dR8mSH', 'required') // Fabric API
dependencies = dependenciesList
changelog = changelogContent
}
githubRelease {
def getenv = System.getenv("GITHUB_TOKEN")
if (getenv) token = getenv
tasks.githubRelease.doFirst {
println "GitHub 令牌: $getenv"
}
owner = "SolidBlock-cn"
repo = "extshape"
tagName = "v$project.mod_version"
targetCommitish = "1.21.1"
body = changelogContent
draft = true
prerelease = false
releaseAssets remapJar, remapSourcesJar
allowUploadToExisting = true
apiEndpoint = "https://api.github.com"
}
publish {
dependsOn tasks.curseforge, tasks.modrinth, tasks.githubRelease
}
gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
if ([rootProject.tasks.curseforge, rootProject.tasks.modrinth, rootProject.tasks.githubRelease, rootProject.tasks.publish].any { graph.hasTask(it) }) {
subprojects {
project.tasks.each { Task subTask ->
subTask.enabled = rootProject.tasks.any { it.dependsOn.contains(subTask) }
}
println "Disabling tasks for subproject $project"
}
}
}
fabricApi {
configureDataGeneration() {
it.modId = "extshape"
}
}