generated from LCLPYT/fabric-mod-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
278 lines (218 loc) · 6.83 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
plugins {
id 'fabric-loom' version '1.9-SNAPSHOT' apply false
id 'maven-publish'
id 'gradle-build-utils' version '1.7.0'
}
Properties props = buildUtils.loadProperties('publish.properties')
ext {
versionPattern = "^[0-9]+\\.[0-9]+\\.[0-9]+(?:[-+][a-zA-Z0-9.]+)?\$"
}
version = buildUtils.gitVersion()
allprojects {
group = project.maven_group
apply plugin: 'java'
apply plugin: 'maven-publish'
def initFile = file('init.gradle')
ext {
isMc = true
}
if (initFile.exists()) {
apply from: initFile
}
if (ext.isMc) {
apply plugin: 'fabric-loom'
}
repositories {
mavenCentral()
maven {
url "https://repo.lclpnet.work/repository/internal"
}
}
dependencies {
compileOnly 'org.jetbrains:annotations:24.1.0'
}
if (ext.isMc) {
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}
}
processResources {
inputs.property "version", project.version
inputs.property "loader_version", project.loader_version
filesMatching("fabric.mod.json") {
expand "version": project.version, "loader_version": project.loader_version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
[jar, sourcesJar].each {
it.from(rootProject.file('LICENSE')) {
rename { "${it}_${project.archivesBaseName}"}
}
}
publishing {
buildUtils.setupPublishRepository(repositories, props)
}
}
subprojects {
version = getSubprojectVersion(project)
if (!ext.isMc) {
configureNonLoomProject(project)
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = project.archivesBaseName
from components.java
}
}
}
publishMavenJavaPublicationToMavenRepository.onlyIf {
return !checkProjectIsDeployed(project, props)
}
}
import work.lclpnet.build.task.GithubDeploymentTask
def env = System.getenv()
tasks.register("github", GithubDeploymentTask) {
dependsOn tasks.remapJar
config {
token = env.get("GITHUB_TOKEN")
repository = env.get("GITHUB_REPOSITORY")
}
release {
title = "[$project.minecraft_version] Kibu $project.version"
tag = buildUtils.latestTag()
}
assets.add(tasks.remapJar.archiveFile.get())
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = project.archivesBaseName
from components.java
pom {
name = 'Kibu'
description = 'Modding library for FabricMC.'
}
}
}
}
// main jar must remap after all the subprojects
subprojects.each {
if (it.ext.isMc) {
remapJar.dependsOn("${it.path}:remapJar")
}
}
sourceSets {
testmod {
compileClasspath += main.compileClasspath + main.getOutput()
runtimeClasspath += main.runtimeClasspath + main.getOutput()
}
}
loom {
runs {
named('server') {
source 'testmod'
}
named('client') {
source 'testmod'
}
}
}
dependencies {
afterEvaluate {
subprojects.each {
api project(path: it.path, configuration: "namedElements")
}
}
}
// add subprojects as nested jar to the main jar
remapJar {
afterEvaluate {
subprojects.each {
if (it.ext.isMc) {
nestedJars.from project(it.path).tasks.named("remapJar")
} else {
nestedJars.from project(it.path).tasks.named("jar")
}
}
}
}
processTestmodResources {
inputs.property "version", project.version
inputs.property "loader_version", project.loader_version
filesMatching("fabric.mod.json") {
expand "version": project.version, "loader_version": project.loader_version
}
}
def checkProjectIsDeployed(Project project, Properties props) {
def url = "${getDeployUrl(props)}/${project.group.toString().replace('.', '/')}/${project.archivesBaseName}/maven-metadata.xml"
String xml
try {
xml = new URL(url).text
} catch (Throwable ignored) {
return false
}
def meta = new groovy.xml.XmlSlurper().parseText(xml)
def versions = meta.versioning.versions.version*.text()
return versions.contains(project.version)
}
def getDeployUrl(Properties props) {
Map<String, String> env = System.getenv()
if (env.containsKey("DEPLOY_URL")) {
return env.get("DEPLOY_URL")
} else if (props.containsKey('mavenHost')) {
return props.getProperty('mavenHost')
} else {
return "file:///${rootProject.projectDir}/repo"
}
}
static def getSubprojectVersion(Project project) {
def version = project.getProperties()["${project.getName()}-version"]
if (!version) {
throw new IllegalStateException("Could not find version for project ${project.getName()}")
}
boolean local = System.getProperty("build.local") == "true"
def suffix = (local ? '+local' : '')
if (!project.ext.isMc) {
return version + suffix
}
def versionString = version.toString()
def snapshotSuffix = "-SNAPSHOT"
if (versionString.endsWith(snapshotSuffix)) {
return versionString.substring(0, versionString.length() - snapshotSuffix.length()) + "+" + project.minecraft_version + suffix + snapshotSuffix
}
return versionString + "+" + project.minecraft_version + suffix
}
static def configureNonLoomProject(Project project) {
// non-loom subprojects need to have a "namedElements" configuration that provides the project artifacts
project.configurations {
namedElements
}
// add the project artifacts to the namedElements configuration
project.apply {
project.artifacts(artifactHandler -> artifactHandler.add("namedElements", project.getTasks().named("jar")));
}
}
def moduleDependencies(project, List<String> dependencies) {
// for each subproject dependency, collect the 'namedElements' configuration
def deps = dependencies.iterator().collect {
project.dependencies.project(path: ":$it", configuration: 'namedElements')
}
// now add the actual dependency to the project
project.dependencies {
deps.each {
api it
}
}
}