Skip to content

feat: remove unnecessary native lib file to reduce zip file size #3742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions ml-algorithms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ plugins {
id "io.freefair.lombok"
id 'com.diffplug.spotless' version '6.25.0'
}
ext {
onnxruntime_version = "1.16.3"
}

repositories {
mavenCentral()
}

configurations {
onnxruntime
}

dependencies {
implementation project(path: ":${rootProject.name}-spi", configuration: 'shadow')
implementation project(path: ":${rootProject.name}-common", configuration: 'shadow')
Expand Down Expand Up @@ -59,11 +66,11 @@ dependencies {
//arm/macos doesn't support GPU
if (os.macOsX || System.getProperty("os.arch") == "aarch64") {
dependencies {
implementation "com.microsoft.onnxruntime:onnxruntime:1.16.3!!"
onnxruntime "com.microsoft.onnxruntime:onnxruntime:${onnxruntime_version}!!"
}
} else {
dependencies {
implementation "com.microsoft.onnxruntime:onnxruntime_gpu:1.16.3!!"
onnxruntime "com.microsoft.onnxruntime:onnxruntime_gpu:${onnxruntime_version}!!"
}
}

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

tasks.register('repackageJar', Jar) {
// Determine which files to exclude based on the current OS
def os = DefaultNativePlatform.currentOperatingSystem
def excludePatterns = []
if (os.windows) {
excludePatterns = ['**/native/linux-*/**', '**/native/osx-*/**']
} else if (os.linux) {
excludePatterns = ['**/native/osx-*/**', '**/native/win-*/**']
} else if (os.macOsX) {
excludePatterns = ['**/native/win-*/**', '**/native/linux-*/**']
}

archiveVersion = onnxruntime_version
archiveBaseName = "onnxruntime-" + os.toFamilyName()

doFirst {
// Get the original JAR file
def originalJarFile = configurations.onnxruntime.singleFile
// Create a temporary directory for extraction
def extractDir = new File(buildDir, "extract-onnxruntime")
extractDir.mkdirs()

// Extract the original JAR
copy {
from zipTree(originalJarFile)
into extractDir
exclude excludePatterns
}

// Set up the repackaged JAR contents
from extractDir
}
}

// Add the repackaged JAR to the implementation configuration
dependencies {
implementation files(repackageJar.archiveFile)
}

// Make sure the repackageJar task runs before the implementation configuration is resolved
compileJava.dependsOn repackageJar
// Make the default build depend on our repackage task
build.dependsOn repackageJar


lombok {
version = "1.18.30"
}
Expand Down
Loading