|
1 | 1 | import java.util.concurrent.Callable
|
| 2 | +import org.opensearch.gradle.dependencies.CompileOnlyResolvePlugin |
2 | 3 |
|
3 | 4 | /*
|
4 | 5 | * Copyright OpenSearch Contributors
|
@@ -30,6 +31,7 @@ plugins {
|
30 | 31 | id 'jacoco'
|
31 | 32 | id 'opensearch.opensearchplugin'
|
32 | 33 | id 'com.diffplug.spotless' version '6.22.0'
|
| 34 | + id 'com.gradleup.shadow' |
33 | 35 | }
|
34 | 36 |
|
35 | 37 | apply plugin: 'opensearch.pluginzip'
|
@@ -148,8 +150,6 @@ spotless {
|
148 | 150 |
|
149 | 151 | dependencies {
|
150 | 152 | compileOnly "org.opensearch:opensearch-job-scheduler-spi:${opensearch_build}"
|
151 |
| - compileOnly "com.google.guava:guava:${guava_version}" |
152 |
| - compileOnly 'com.google.guava:failureaccess:1.0.2' |
153 | 153 |
|
154 | 154 | api "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
|
155 | 155 | api "com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}"
|
@@ -220,12 +220,57 @@ testingConventions.enabled = false
|
220 | 220 | // TODO: need to verify the thirdPartyAudit
|
221 | 221 | // currently it complains missing classes like ibatis, mysql etc, should not be a problem
|
222 | 222 | thirdPartyAudit.enabled = false
|
223 |
| - |
| 223 | +tasks.named("publishShadowPublicationToMavenLocal") { |
| 224 | + dependsOn tasks.named("generatePomFileForNebulaPublication") |
| 225 | +} |
224 | 226 | apply plugin: 'com.netflix.nebula.ospackage'
|
225 | 227 | validateNebulaPom.enabled = false
|
226 |
| - |
| 228 | +generatePomFileForShadowPublication.enabled = false |
| 229 | +validateShadowPom.enabled = false |
| 230 | +//generatePomFileForShadowPublication.enabled = false |
227 | 231 | // This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
|
228 | 232 | afterEvaluate {
|
| 233 | + tasks.named("bundlePlugin", Zip).configure { zipTask -> |
| 234 | + zipTask.doLast { |
| 235 | + def zipFile = zipTask.archiveFile.get().asFile |
| 236 | + println "Original bundlePlugin ZIP: ${zipFile.absolutePath}" |
| 237 | + |
| 238 | + // Create a temporary directory for processing |
| 239 | + def tempDir = file("$buildDir/tempBundle") |
| 240 | + delete(tempDir) |
| 241 | + tempDir.mkdirs() |
| 242 | + |
| 243 | + // Extract the ZIP into the temporary directory |
| 244 | + copy { |
| 245 | + from zipTree(zipFile) |
| 246 | + into tempDir |
| 247 | + } |
| 248 | + println "Extracted ZIP to: ${tempDir.absolutePath}" |
| 249 | + |
| 250 | + // Determine the relocated jar produced by shadowJar. |
| 251 | + def relocatedJar = shadowJar.archiveFile.get().asFile |
| 252 | + def jarName = relocatedJar.getName() |
| 253 | + println "Relocated jar to keep: ${jarName}" |
| 254 | + |
| 255 | + // Delete all jar files (files ending with .jar) that are not the relocated jar. |
| 256 | + fileTree(dir: tempDir, includes: ['**/*.jar']).each { File jarFile -> |
| 257 | + if (!jarFile.getName().equals(jarName)) { |
| 258 | + println "Deleting jar file: ${jarFile.absolutePath}" |
| 259 | + jarFile.delete() |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + // Reassemble the ZIP using the remaining files |
| 264 | + ant.zip(destfile: zipFile) { |
| 265 | + fileset(dir: tempDir) |
| 266 | + } |
| 267 | + println "Final bundlePlugin ZIP updated: ${zipFile.absolutePath}" |
| 268 | + |
| 269 | + // Clean up the temporary directory |
| 270 | + delete(tempDir) |
| 271 | + } |
| 272 | + } |
| 273 | + |
229 | 274 | ospackage {
|
230 | 275 | packageName = "${rootProject.name}"
|
231 | 276 | release = isSnapshot ? "0.1" : '1'
|
@@ -317,3 +362,22 @@ run {
|
317 | 362 | useCluster testClusters.integTest
|
318 | 363 | }
|
319 | 364 |
|
| 365 | +def compileOnlyResolveableFiles = project.configurations.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME).files |
| 366 | +shadowJar { |
| 367 | + configurations = [project.configurations.runtimeClasspath] |
| 368 | + exclude { details -> |
| 369 | + def file = details.file |
| 370 | + return compileOnlyResolveableFiles.contains(file) |
| 371 | + } |
| 372 | + |
| 373 | + destinationDirectory = file("${project.buildDir}/distributions") |
| 374 | + archiveClassifier.set(null) |
| 375 | + |
| 376 | + exclude 'META-INF/maven/com.google.guava/**' |
| 377 | + exclude 'com/google/thirdparty/**' |
| 378 | + exclude 'org/opensearch/jobscheduler/**' |
| 379 | + exclude 'org/apache/lucene/**' |
| 380 | + |
| 381 | + relocate 'com.google.common', 'shaded.com.google.common' |
| 382 | + relocate 'org.joda.time', 'shaded.org.joda.time' |
| 383 | +} |
0 commit comments