-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathbuild.gradle
More file actions
298 lines (249 loc) · 9.97 KB
/
build.gradle
File metadata and controls
298 lines (249 loc) · 9.97 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
plugins {
id 'application'
id 'java'
id 'io.freefair.lombok' version '8.6'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'idea'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.3'
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import groovy.json.JsonOutput
apply from: 'gradle/project-config.gradle'
apply from: 'gradle/plugin-utils.gradle'
def microbotClientVersion = project.ext.getMicrobotClientVersion()
def microbotClientPath = project.findProperty("microbotClientPath")
if (!microbotClientPath && project.hasProperty("microbotClientDir")) {
def clientDir = file(project.findProperty("microbotClientDir"))
if (clientDir.isDirectory()) {
def match = clientDir.listFiles()?.findAll { it.name ==~ /microbot-.*\.jar/ && !it.name.contains('sources') && !it.name.contains('shaded') }
?.sort { -it.lastModified() }
?.first()
if (match) {
microbotClientPath = match.absolutePath
logger.lifecycle("🤖 Resolved local microbot client JAR: ${microbotClientPath}")
}
}
}
// Java toolchain configuration
java {
toolchain {
languageVersion = JavaLanguageVersion.of(project.ext.TARGET_JDK_VERSION)
vendor = JvmVendorSpec."${project.ext.JDK_VENDOR}"
}
}
idea {
module {
downloadSources = false
}
project {
settings {
delegateActions {
delegateBuildRunToGradle = false
testRunner = 'PLATFORM'
}
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = project.ext.TARGET_JDK_VERSION
options.compilerArgs.addAll([
'-parameters',
'-Xlint:none',
'-g'
])
options.fork = true
options.forkOptions.jvmArgs = ['-Dfile.encoding=UTF-8']
}
configurations {
microbotRuntime {
canBeConsumed = false
canBeResolved = true
}
pluginShadowClasspath {
extendsFrom runtimeClasspath
exclude group: 'net.runelite', module: 'microbot'
}
// Disable source downloads for all configurations and rewrite legacy coordinates
configureEach {
resolutionStrategy {
dependencySubstitution {
substitute module("com.microbot:client") using module("com.microbot:microbot:${microbotClientVersion}")
}
eachDependency { details ->
if (details.target.group == 'com.microbot' && details.target.name == 'microbot') {
details.artifactSelection {
selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, null)
}
}
}
}
}
}
repositories {
ivy {
name = "microbot-client-github-releases"
url = uri(project.ext.getGithubClientBaseUrl())
patternLayout {
artifact "[revision]/[module]-[revision].[ext]"
artifact "[revision]/microbot-[revision].[ext]"
}
metadataSources { artifact() }
}
mavenCentral()
}
dependencies {
if (microbotClientPath) {
def clientFile = file(microbotClientPath)
if (!clientFile.exists()) {
throw new GradleException("microbotClientPath does not exist: ${clientFile}")
}
compileOnly files(clientFile)
microbotRuntime files(clientFile)
testImplementation files(clientFile)
} else {
compileOnly "com.microbot:microbot:${microbotClientVersion}@jar"
microbotRuntime "com.microbot:microbot:${microbotClientVersion}@jar"
testImplementation "com.microbot:microbot:${microbotClientVersion}@jar"
}
}
application {
// Replace this with the actual main class inside your shaded jar
mainClass = 'net.runelite.client.RuneLite'
}
tasks.register('runDebug', JavaExec) {
group = 'application'
description = 'Launch the Microbot client via the test entry point (Microbot.java) with pluginsToDebug populated.'
dependsOn 'testClasses'
classpath = sourceSets.test.runtimeClasspath
mainClass = 'net.runelite.client.Microbot'
}
// Plugin Logic
String pluginVersionFromPluginJson(File pluginDir) {
def pluginJavaFile = pluginDir.listFiles()?.find { it.name.endsWith("Plugin.java") }
if (pluginJavaFile == null) {
throw new GradleException("No *Plugin.java found in: $pluginDir")
}
def info = ext.getPluginDescriptorInfo(pluginJavaFile) as Map // ext == project.ext
return info.version as String
}
// Discover and filter plugins
afterEvaluate {
def microbotConfig = configurations.microbotRuntime.resolvedConfiguration
def microbotDependency = microbotConfig.firstLevelModuleDependencies
.find { it.moduleGroup == 'com.microbot' && it.moduleName == 'microbot' }
if (microbotDependency) {
logger.lifecycle("🤖 Microbot Client Version: ${microbotDependency.moduleVersion}")
} else {
if (microbotClientPath) {
logger.lifecycle("🤖 Microbot Client (local path): ${microbotClientPath}")
} else {
logger.warn("⚠️ Could not determine microbot client version")
}
}
def pluginsDir = file(project.ext.getPluginsSourcePath())
def allPlugins = project.ext.discoverPlugins(pluginsDir)
def pluginsProperty = project.findProperty("pluginList")
def selectedPluginNames = pluginsProperty ? pluginsProperty.split(',').collect { it.trim() } : []
def validPlugins = allPlugins.findAll { plugin ->
if (selectedPluginNames && !selectedPluginNames.contains(plugin.name)) {
logger.info("Skipping plugin: ${plugin.name}")
return false
}
logger.info("Processing plugin: ${plugin.name}")
return true
}
println "Detected plugins: ${allPlugins*.name}"
println "Processing plugins: ${validPlugins*.name}"
ext.validPlugins = validPlugins
ext.allPlugins = allPlugins
def pluginPublications = []
validPlugins.each { plugin ->
// Configure source set
project.ext.configurePluginSourceSet(plugin)
// Configure dependencies
def pluginConfigName = project.ext.configurePluginDependencies(plugin)
// Create JAR task using the configuration
def jarTask = tasks.register("${plugin.name}Jar", ShadowJar, project.ext.getPluginJarTaskConfig(plugin, pluginConfigName))
// Add to build dependencies
tasks.named("build") {
dependsOn(jarTask)
}
// Collect for publishing
pluginPublications << [
name : plugin.name,
jarTask : jarTask,
version : pluginVersionFromPluginJson(plugin.dir)
]
}
// Configure test source set to have access to all plugin source sets
def allPluginCompileTasks = []
validPlugins.each { plugin ->
def compileTaskName = "compile${plugin.sourceSetName.capitalize()}Java"
if (sourceSets.findByName(plugin.sourceSetName)) {
sourceSets.test.compileClasspath += sourceSets."${plugin.sourceSetName}".output
sourceSets.test.runtimeClasspath += sourceSets."${plugin.sourceSetName}".output
allPluginCompileTasks.add(compileTaskName)
dependencies.add('testRuntimeOnly', sourceSets."${plugin.sourceSetName}".output)
dependencies.add('testCompileOnly', sourceSets."${plugin.sourceSetName}".output)
}
}
tasks.named('compileTestJava').configure {
dependsOn allPluginCompileTasks
}
tasks.named('test').configure {
dependsOn allPluginCompileTasks
}
}
tasks.register("copyPluginDocs") {
group = "documentation"
description = "Copies plugin README.md files and resources to the public directory for GitHub Pages"
doLast {
def publicDir = file(project.ext.getDocsOutputPath())
publicDir.mkdirs()
def pluginsDir = file(project.ext.getPluginsSourcePath())
def allPlugins = project.ext.discoverPlugins(pluginsDir)
def pluginsProperty = project.findProperty("pluginList")
def selectedPluginNames = pluginsProperty ? pluginsProperty.split(',').collect { it.trim() } : []
def validPlugins = allPlugins.findAll { plugin ->
if (selectedPluginNames && !selectedPluginNames.contains(plugin.name)) {
return false
}
return true
}
validPlugins.each { plugin ->
project.ext.copyPluginDocumentation(plugin, publicDir)
}
}
}
// Validating JDK version when generating plugins.json is important to ensure consistent hashing :(
tasks.register("generatePluginsJson") {
group = "build"
description = "Generates plugins.json by scanning plugin folders and hashing JARs"
dependsOn 'validateJdkVersion'
doLast {
def pluginRoot = file(project.ext.getPluginsSourcePath())
def outputJson = file("${project.ext.getDocsOutputPath()}/plugins.json")
def jarOutputDir = file("$buildDir/libs")
def allPlugins = project.ext.discoverPlugins(pluginRoot)
def plugins = project.ext.generatePluginsJsonData(allPlugins, jarOutputDir)
outputJson.parentFile.mkdirs()
outputJson.text = JsonOutput.prettyPrint(JsonOutput.toJson(plugins))
logger.info("✅ Generated plugins.json with ${plugins.size()} plugins")
}
}
tasks.register('validateJdkVersion') {
group = 'verification'
description = 'Validates that the correct JDK version is being used'
doLast {
def currentJdkVersion = System.getProperty('java.version')
def expectedVersion = project.ext.TARGET_JDK_VERSION
// Extract major version from full version string (e.g., "11.0.28" -> 11)
def majorVersion = currentJdkVersion.split('\\.')[0] as Integer
if (majorVersion != expectedVersion) {
logger.log(LogLevel.WARN, "❌ JDK version mismatch! Expected JDK ${expectedVersion}, but found JDK ${majorVersion} (${currentJdkVersion})")
} else {
logger.lifecycle("✅ JDK version validated: ${currentJdkVersion}")
}
}
}