@@ -12,11 +12,18 @@ plugins {
12
12
id " io.freefair.lombok"
13
13
id ' com.diffplug.spotless' version ' 6.25.0'
14
14
}
15
+ ext {
16
+ onnxruntime_version = " 1.16.3"
17
+ }
15
18
16
19
repositories {
17
20
mavenCentral()
18
21
}
19
22
23
+ configurations {
24
+ onnxruntime
25
+ }
26
+
20
27
dependencies {
21
28
implementation project(path : " :${ rootProject.name} -spi" , configuration : ' shadow' )
22
29
implementation project(path : " :${ rootProject.name} -common" , configuration : ' shadow' )
@@ -59,11 +66,11 @@ dependencies {
59
66
// arm/macos doesn't support GPU
60
67
if (os. macOsX || System . getProperty(" os.arch" ) == " aarch64" ) {
61
68
dependencies {
62
- implementation " com.microsoft.onnxruntime:onnxruntime:1.16.3 !!"
69
+ onnxruntime " com.microsoft.onnxruntime:onnxruntime:${ onnxruntime_version } !!"
63
70
}
64
71
} else {
65
72
dependencies {
66
- implementation " com.microsoft.onnxruntime:onnxruntime_gpu:1.16.3 !!"
73
+ onnxruntime " com.microsoft.onnxruntime:onnxruntime_gpu:${ onnxruntime_version } !!"
67
74
}
68
75
}
69
76
@@ -91,6 +98,51 @@ dependencies {
91
98
testImplementation group : ' com.networknt' , name : ' json-schema-validator' , version : ' 1.4.0'
92
99
}
93
100
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
+
94
146
lombok {
95
147
version = " 1.18.30"
96
148
}
0 commit comments