Skip to content

Commit cb0b563

Browse files
committed
reduce zip file size
Signed-off-by: Hailong Cui <ihailong@amazon.com>
1 parent 2da7d7a commit cb0b563

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

ml-algorithms/build.gradle

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ plugins {
1212
id "io.freefair.lombok"
1313
id 'com.diffplug.spotless' version '6.25.0'
1414
}
15+
ext {
16+
onnxruntime_version = "1.16.3"
17+
}
1518

1619
repositories {
1720
mavenCentral()
1821
}
1922

23+
configurations {
24+
onnxruntime
25+
}
26+
2027
dependencies {
2128
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
2229
implementation project(path: ":${rootProject.name}-common", configuration: 'shadow')
@@ -59,11 +66,11 @@ dependencies {
5966
//arm/macos doesn't support GPU
6067
if (os.macOsX || System.getProperty("os.arch") == "aarch64") {
6168
dependencies {
62-
implementation "com.microsoft.onnxruntime:onnxruntime:1.16.3!!"
69+
onnxruntime "com.microsoft.onnxruntime:onnxruntime:${onnxruntime_version}!!"
6370
}
6471
} else {
6572
dependencies {
66-
implementation "com.microsoft.onnxruntime:onnxruntime_gpu:1.16.3!!"
73+
onnxruntime "com.microsoft.onnxruntime:onnxruntime_gpu:${onnxruntime_version}!!"
6774
}
6875
}
6976

@@ -91,6 +98,51 @@ dependencies {
9198
testImplementation group: 'com.networknt' , name: 'json-schema-validator', version: '1.4.0'
9299
}
93100

101+
tasks.register('repackageJar', Jar) {
102+
// Determine which files to exclude based on the current OS
103+
def os = DefaultNativePlatform.currentOperatingSystem
104+
def excludePatterns = []
105+
if (os.windows) {
106+
excludePatterns = ['**/native/linux-*/**', '**/native/osx-*/**']
107+
} else if (os.linux) {
108+
excludePatterns = ['**/native/osx-*/**', '**/native/win-*/**']
109+
} else if (os.macOsX) {
110+
excludePatterns = ['**/native/win-*/**', '**/native/linux-*/**']
111+
}
112+
113+
archiveVersion = onnxruntime_version
114+
archiveBaseName = "onnxruntime-" + os.toFamilyName()
115+
116+
doFirst {
117+
// Get the original JAR file
118+
def originalJarFile = configurations.onnxruntime.singleFile
119+
// Create a temporary directory for extraction
120+
def extractDir = new File(buildDir, "extract-onnxruntime")
121+
extractDir.mkdirs()
122+
123+
// Extract the original JAR
124+
copy {
125+
from zipTree(originalJarFile)
126+
into extractDir
127+
exclude excludePatterns
128+
}
129+
130+
// Set up the repackaged JAR contents
131+
from extractDir
132+
}
133+
}
134+
135+
// Add the repackaged JAR to the implementation configuration
136+
dependencies {
137+
implementation files(repackageJar.archiveFile)
138+
}
139+
140+
// Make sure the repackageJar task runs before the implementation configuration is resolved
141+
compileJava.dependsOn repackageJar
142+
// Make the default build depend on our repackage task
143+
build.dependsOn repackageJar
144+
145+
94146
lombok {
95147
version = "1.18.30"
96148
}

0 commit comments

Comments
 (0)