-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
277 lines (225 loc) · 7.78 KB
/
build.gradle
File metadata and controls
277 lines (225 loc) · 7.78 KB
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
import org.mangorage.mangobotgradle.util.GitVersion
buildscript {
repositories {
gradlePluginPortal()
maven {
url = "https://maven.minecraftforge.net/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("com.gradleup.shadow:shadow-gradle-plugin:+")
classpath 'org.mangorage:MangoBotGradle:5.0.13'
}
}
plugins {
id 'net.darkhax.curseforgegradle' version '1.1.26'
}
apply plugin: "com.gradleup.shadow"
apply plugin: 'java'
apply plugin: 'maven-publish'
def jda_version = '5.3.2'
def commitInfo = GitVersion.getGitVersion()
group = 'org.mangorage'
version = "$jda_version" + "-" + commitInfo.getVersionAsString()
println(version)
println(commitInfo.getLastCommitMessage())
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
tasks.withType(JavaExec).configureEach {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(8))
})
}
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
configurations {
embedLibrary {
extendsFrom implementation
}
}
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
embedLibrary("net.dv8tion:JDA:$jda_version")
}
test {
useJUnitPlatform()
}
tasks.named('processResources', ProcessResources).configure {
eachFile { details ->
println "Processing file: ${details.path}"
}
filesMatching("fabric.mod.json") {
println "Expanding properties in: ${path}"
expand([
jda_library_version: version
] + [project: project])
}
}
shadowJar {
enableRelocation = true
relocationPrefix = "org.mangorage.embed"
archiveClassifier.set("")
configurations = [project.configurations.embedLibrary]
manifest {
attributes(
[
'FmlModType': 'LIBRARY'
]
)
}
relocate("net.dv8tion.jda", 'net.dv8tion.jda')
}
task publishCurseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
group "modpublishing"
afterEvaluate {
apiToken = System.getenv("CURSEFORGE_TOKEN")
}
def projectId = 1225448
def mainFile = upload(projectId, shadowJar)
mainFile.releaseType = "release"
mainFile.displayName = "JDA Library " + project.version
mainFile.changelog = commitInfo.lastCommitMessage()
mainFile.addModLoader("forge")
mainFile.addModLoader("neoforge")
mainFile.addModLoader("fabric")
List<String> gameVersions = [
'1.0.0', '1.0',
'1.1',
'1.2.1', '1.2.2', '1.2.3', '1.2.4', '1.2.5',
'1.3.1', '1.3.2',
'1.4.2', '1.4.4', '1.4.5', '1.4.6', '1.4.7',
'1.5.1', '1.5.2', '1.5.3',
'1.6.1', '1.6.2', '1.6.4',
'1.7.10', '1.7.9', '1.7.8', '1.7.7', '1.7.6', '1.7.5', '1.7.4', '1.7.3', '1.7.2',
'1.8', '1.8.1', '1.8.2', '1.8.3', '1.8.4', '1.8.5', '1.8.6', '1.8.7', '1.8.8', '1.8.9',
'1.9', '1.9.1', '1.9.2', '1.9.3', '1.9.4',
'1.10', '1.10.1', '1.10.2',
'1.11', '1.11.1', '1.11.2',
'1.12', '1.12.1', '1.12.2',
'1.13', '1.13.1', '1.13.2',
'1.14', '1.14.1', '1.14.2', '1.14.3', '1.14.4',
'1.15', '1.15.1', '1.15.2',
'1.16', '1.16.1', '1.16.2', '1.16.3', '1.16.4', '1.16.5',
'1.17', '1.17.1',
'1.18', '1.18.1', '1.18.2',
'1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4',
'1.20', '1.20.1', '1.20.2', '1.20.3', '1.20.4', '1.20.5', '1.20.6',
'1.21', '1.21.1', '1.21.2', '1.21.3', '1.21.4', '1.21.5'
]
// Loop through the list and add each game version
gameVersions.each { version ->
mainFile.addGameVersion(version)
}
}
tasks.register('shadowJavadocJar', Jar) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
dependsOn javadoc
doFirst {
delete javadoc.destinationDir
javadoc.destinationDir.mkdirs()
}
}
import org.apache.tools.ant.taskdefs.Expand
import org.apache.tools.ant.taskdefs.Replace
task fetchSources {
doLast {
configurations.embedLibrary.resolvedConfiguration.lenientConfiguration.artifacts.each { artifact ->
def depModuleIdentifier = artifact.moduleVersion.id.module
def group = depModuleIdentifier.group
def name = depModuleIdentifier.name
def version = artifact.moduleVersion.id.version
// Construct the source artifact dependency
def sourceDependency = dependencies.create("${group}:${name}:${version}:sources")
// Resolve the source artifact
def sourceArtifacts = configurations.detachedConfiguration(sourceDependency).resolvedConfiguration.lenientConfiguration.artifacts
sourceArtifacts.each { sourceArtifact ->
// Copy the source artifact to a location for inclusion in the JAR
def tempDir = file("$buildDir/tmp/sources_original")
copy {
from zipTree(sourceArtifact.file)
into tempDir
}
// Relocate the source code
fileTree(dir: tempDir).each { file ->
if (file.name.endsWith(".java")) {
logger.info("Processing file: ${file.absolutePath}")
def originalPackage = findOriginalPackage(file)
logger.info("Original package: ${originalPackage}")
if (originalPackage) {
def newPackage = "org.mangorage.embed." + originalPackage
// Replace package declaration
// Crude, but you know better
def content = file.text
def originalContent = content // Store original content for comparison
content = content.replace("package " + originalPackage + ";", "package " + newPackage + ";")
// Logging the file after changes
logger.info("File after relocation ${content}")
if (content != originalContent) {
file.write(content)
} else {
logger.warn("No change after relocation")
}
} else {
logger.warn("No package found in file")
}
}
}
copy {
from tempDir
into "$buildDir/tmp/sources"
}
tempDir.deleteDir()
}
}
}
}
def findOriginalPackage(File file) {
def content = file.text
def match = content =~ /package (.*?);/
if (match.find()) {
return match.group(1)
}
return null
}
task shadowSourcesJar(type: Jar) {
dependsOn fetchSources
archiveClassifier = 'sources'
from "$buildDir/tmp/sources"
doLast {
file("$buildDir/tmp/sources").deleteDir()
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = "JDA-Library"
artifact(shadowJar) // The main JAR
}
}
repositories {
maven {
url = "https://maven.minecraftforge.net/"
credentials {
username = System.getenv("MAVEN_USER")
password = System.getenv("MAVEN_PASSWORD")
}
}
maven {
name = "localMaven"
url = layout.buildDirectory.dir("repo")
}
}
}