Skip to content

Commit e8c80b6

Browse files
authored
[Java] Add a dependency on onnxruntime (#2030) (#2040)
This PR addresses the concern raised in #2030 (and before in microsoft/onnxruntime#27656) regarding the missing dependency between `onnxruntime-genai` and the core `onnxruntime` Java artifact. Currently, `GenAI.java` assumes that the native ONNX Runtime libraries are available on the classpath and attempts to load them directly. However, without an explicit Maven dependency, this is not guaranteed and can lead to runtime issues. Additionally, this setup duplicates native library loading logic that already exists in `OrtRuntime.java`, creating unnecessary maintenance overhead and inconsistencies (e.g., missing extraction of `onnxruntime_providers_shared`). Other ecosystem packages already declare this dependency: * The NuGet package includes a [dependency on ONNX Runtime](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntimeGenAI) * The PyPI package does as well (see the `METADATA` file in a [onnxruntime-genai wheel](https://pypi.org/project/onnxruntime-genai)) Aligning the Java package with this behavior ensures consistency across platforms and provides a more predictable and reliable setup for users. Adding this dependency makes the expectation explicit and lays the groundwork for potentially reusing the existing native loading logic in the future.
1 parent 80dd558 commit e8c80b6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/java/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def mavenUser = System.properties['mavenUser']
3939
def mavenPwd = System.properties['mavenPwd']
4040
def mavenArtifactId = useCUDA == null ? project.name : project.name + "_gpu"
4141

42+
def onnxruntimeArtifactId = useCUDA == null ? "onnxruntime" : "onnxruntime_gpu"
43+
def onnxruntimeVersion = System.properties["ONNXRUNTIME_VERSION"] ?: "1.23.0"
44+
4245
def defaultDescription = 'ONNX Runtime GenAI is <TODO>'
4346

4447
logger.lifecycle("cmakeBuildDir:${cmakeBuildDir}")
@@ -160,6 +163,7 @@ if (cmakeNativeLibDir != null) {
160163
}
161164

162165
dependencies {
166+
implementation "com.microsoft.onnxruntime:${onnxruntimeArtifactId}:${onnxruntimeVersion}"
163167
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
164168
testImplementation 'org.junit.platform:junit-platform-launcher:1.10.1'
165169
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'

0 commit comments

Comments
 (0)