-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathbuild.gradle
executable file
·303 lines (258 loc) · 12.6 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
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
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id "net.neoforged.gradle.common"
}
apply from: 'https://raw.githubusercontent.com/ldtteam/OperaPublicaCreator/main/gradle/modules/git.gradle'
apply from: 'https://raw.githubusercontent.com/ldtteam/OperaPublicaCreator/main/gradle/modules/util.gradle'
project.group = "mod.chiselsandbits"
project.version = opc.buildVersionNumberWithOffset(
(System.getenv().containsKey("Version") ? System.getenv("Version") : project.localVersion),
project.minecraftVersion,
opc.getProperty("sourceVersionName"),
opc.getIntProperty("sourceVersionElementIndex"),
opc.getIntProperty("mcVersionElementIndex")
)
//Configure extension utility methods on all subprojects.
subprojects { Project subProject ->
subProject.ext.disableCompiling = {
subProject.tasks.build.enabled = false
subProject.tasks.jar.enabled = false
subProject.tasks.processResources.enabled = false
subProject.tasks.assemble.enabled = false
subProject.tasks.compileJava.enabled = false
subProject.tasks.classes.enabled = false
subProject.tasks.test.enabled = false
subProject.tasks.testClasses.enabled = false
subProject.tasks.check.enabled = false
}
subProject.ext.addInnerProject = { String projectName ->
Project coreProject = subProject.project(projectName);
subProject.dependencies.api (coreProject) {
exclude group: 'net.minecraft', module: 'joined'
}
if (subProject.getPlugins().hasPlugin("net.neoforged.gradle.userdev")) {
subProject.jarJar.enable()
subProject.dependencies.jarJar (coreProject) {
jarJar.ranged(it, "[${coreProject.version}]")
jarJar.pin(it, coreProject.version)
exclude group: 'net.minecraft', module: 'joined'
}
}
else if (subProject.getPlugins().hasPlugin("fabric-loom") && subProject.ext.remapTaskClass != null) {
Provider<File> fmjFile = subProject.layout.buildDirectory.dir("fabric-meta-generation").map {it.dir(coreProject.name) }
.map { it.file("fabric.mod.json") }
.map { RegularFile file -> {
def targetFile = file.asFile;
File parentDir = targetFile.parentFile;
parentDir.mkdirs();
targetFile.newWriter().withWriter { w -> w << """
{
"schemaVersion": 1,
"id": "${coreProject.group.replace(".", "_")}_${coreProject.name}",
"version": "${coreProject.version}",
"name": "${coreProject.name}",
"custom": {
"fabric-loom:generated": true
}
}
""".trim() }
return file
}}
def remapCommonJarTask = subProject.tasks.register("remap${coreProject.name.capitalize()}Jar", subProject.ext.remapTaskClass) {
input = coreProject.tasks.jar.archiveFile
archiveClassifier = "${coreProject.name}-fabric"
from(fmjFile)
}
subProject.remapJar {
nestedJars.from(remapCommonJarTask.get().archiveFile)
}
def outgoingConfiguration = coreProject.configurations.create("remappedRuntimeElements")
outgoingConfiguration.canBeResolved = false
outgoingConfiguration.extendsFrom(coreProject.configurations.runtimeElements)
def remappedAttribute = Attribute.of("net.fabric.loom.remapped", Boolean)
outgoingConfiguration.attributes { attributes ->
attributes.attribute(remappedAttribute, true)
}
AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) coreProject.components.findByName("java")
javaComponent.addVariantsFromConfiguration(outgoingConfiguration) {
// dependencies for this variant are considered runtime dependencies
it.mapToMavenScope("runtime")
// and also optional dependencies, because we don't want them to leak
it.mapToOptional()
}
coreProject.artifacts.add('remappedRuntimeElements', remapCommonJarTask.get().archiveFile) {
type = 'jar'
builtBy remapCommonJarTask.get()
}
}
}
subProject.ext.addApiProject = {
subProject.addInnerProject(':api')
}
subProject.ext.addCoreProject = {
subProject.addInnerProject(':core')
}
subProject.ext.determineNextMajorVersion = { v ->
def components = v.split("\\.")
def major = components[0].toInteger()
return "${major + 1}.0.0".toString()
}
subProject.ext.buildSupportedVersionRange = { v ->
def nextMajorComponent = determineNextMajorVersion(v)
return "[${v},${nextMajorComponent})".toString()
}
subProject.ext.getIdentifiers = {
def propertiesToExpand = [
"version" : project.version,
"name" : rootProject.name.toString(),
"id" : rootProject.modId,
"description" : (rootProject.description == null ? "" : rootProject.description).toString(),
"author" : rootProject.author.toString(),
"sources" : rootProject.githubUrl.toString(),
"package" : "${rootProject.group}.${subProject.name.toLowerCase()}".toString(),
"forgeVersion" : project.forgeVersion,
"minecraftVersion" : project.minecraftVersion,
"supportedScenaVersionRange": buildSupportedVersionRange(project.scenaVersion),
"scenaVersion" : project.scenaVersion,
"fabricVersion" : project.fabricVersion,
"fabricLoaderVersion" : project.fabricLoaderVersion,
]
return propertiesToExpand
}
subProject.ext.setupResourceProcessing = { copyTask ->
copyTask.rename({ fileName ->
if (fileName != "mixins.json") {
return fileName
} else {
return "${rootProject.name.toLowerCase()}.mixins.json"
}
})
copyTask.filesMatching(["META-INF/mods.toml", "pack.mcmeta", "mixins.json", "${rootProject.name.toLowerCase()}.mixins.json".toString(), "fabric.mod.json"]) {
filter(ReplaceTokens, tokens: getIdentifiers())
}
copyTask.getInputs().properties(getIdentifiers())
}
subProject.tasks.withType(Jar.class).configureEach { jarTask ->
jarTask.archiveBaseName = "${rootProject.name}-${subProject.name}"
jarTask.manifest.attributes([
"Specification-Title" : rootProject.name,
"Specification-Vendor" : rootProject.creator,
"Specification-Version" : rootProject.version,
"Implementation-Title" : rootProject.name,
"Implementation-Version" : rootProject.version,
"Implementation-Vendor" : rootProject.creator,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"Automatic-Module-Name" : rootProject.name.toLowerCase().replace("-", "_") + "_" + subProject.name.toLowerCase().replace("-", "_"),
"FMLModType": "GAMELIBRARY"
])
jarTask.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
subprojects { subProject ->
subProject.apply { configure ->
configure.plugin("idea")
configure.plugin("java")
configure.plugin("java-library")
configure.plugin("maven-publish")
}
subProject.apply from: 'https://raw.githubusercontent.com/ldtteam/OperaPublicaCreator/main/gradle/modules/git.gradle'
subProject.apply from: 'https://raw.githubusercontent.com/ldtteam/OperaPublicaCreator/main/gradle/modules/util.gradle'
subProject.archivesBaseName = "${rootProject.name}-${subProject.name}"
subProject.repositories.mavenLocal()
subProject.repositories.mavenCentral()
subProject.repositories.maven {
name 'LDTTeam - Modding'
url 'https://ldtteam.jfrog.io/ldtteam/modding/'
}
subProject.repositories.maven {
name = 'TTerag maven'
url = 'https://maven.tterrag.com/'
}
subProject.group = rootProject.group
subProject.version = rootProject.version
subProject.java.toolchain.languageVersion.set(JavaLanguageVersion.of(project.javaVersion))
subProject.publishing.repositories.maven {
name 'InternalDirectory'
url 'file://' + rootProject.file('repo').getAbsolutePath()
}
subProject.dependencies.compileOnly "org.jetbrains:annotations:${project.jetbrainsAnnotationsVersion}"
subProject.dependencies.testCompileOnly "org.jetbrains:annotations:${project.jetbrainsAnnotationsVersion}"
tasks.withType(Javadoc.class).configureEach { Javadoc task ->
task.options.tags(
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:',
'reason:a:The reason for adding an @Overwrite'
)
}
subProject.afterEvaluate {
if (subProject.tasks.build.enabled) {
subProject.publishing {
publications {
mavenJava(MavenPublication) { pub ->
artifactId "${rootProject.name}-${subProject.name}"
from subProject.components.java
pom {
url = subProject.githubUrl
licenses {
license {
name = 'GNU GENERAL PUBLIC LICENSE Version 3'
url = 'https://www.gnu.org/licenses/gpl-3.0.en.html'
}
}
developers {
developer {
id = 'OrionDevelopment'
name = 'Marc Hermans'
email = '[email protected]'
}
}
scm {
connection = subProject.gitUrl
developerConnection = subProject.gitConnectUrl
url = subProject.projectUrl
}
}
}
}
if (System.getenv().containsKey("LDTTeamJfrogUsername") && System.getenv().containsKey("LDTTeamJfrogPassword")) {
repositories {
maven {
name 'LDTTeamJfrog'
credentials {
username System.getenv().get("LDTTeamJfrogUsername")
password System.getenv().get("LDTTeamJfrogPassword")
}
url 'https://ldtteam.jfrog.io/ldtteam/mods-maven'
}
}
}
}
}
}
}
task("createChangelog") {
group = 'publishing'
doLast {
def teamCityURL = "https://buildsystem.ldtteam.com/"
project.rootProject.file("build/changelog.md").parentFile.mkdirs()
def file = new FileOutputStream(project.rootProject.file("build/changelog.md"))
def out = new BufferedOutputStream(file)
def changesXML = new XmlSlurper().parse(teamCityURL + "guestAuth/app/rest/changes?locator=build:(id:" + teamcity["teamcity.build.id"] + ")")
def changes = changesXML.change
out << "# ${project.name} Changelog \n"
out << "## Version: _" + version + "_ \n"
out << "### Changes: \n"
if (changes.size() > 0) {
for (int i = 0; i < changes.size(); i++) {
def changeDetailsURL = teamCityURL + "guestAuth/app/rest/changes/id:" + changes[i][email protected]()
def changeDetailsXml = new XmlSlurper().parse(changeDetailsURL)
def changeComment = changeDetailsXml.comment.text().trim()
out << "* " + changeComment + "\n"
}
} else {
out << "_No Changes detected!_"
}
out.close()
}
}