diff --git a/cmake/onnxruntime_java.cmake b/cmake/onnxruntime_java.cmake index f29a9f918c..1a9bf4795a 100644 --- a/cmake/onnxruntime_java.cmake +++ b/cmake/onnxruntime_java.cmake @@ -42,6 +42,9 @@ set(GRADLE_ARGS clean jar) if(WIN32) set(GRADLE_ARGS ${GRADLE_ARGS} -Dorg.gradle.daemon=false) endif() +if(onnxruntime_USE_CUDA) + set(GRADLE_ARGS ${GRADLE_ARGS} -DUSE_CUDA=1) +endif() add_custom_command(OUTPUT ${JAVA_OUTPUT_JAR} COMMAND ${GRADLE_EXECUTABLE} ${GRADLE_ARGS} WORKING_DIRECTORY ${JAVA_ROOT} DEPENDS ${onnxruntime4j_gradle_files} ${onnxruntime4j_src}) add_custom_target(onnxruntime4j DEPENDS ${JAVA_OUTPUT_JAR}) set_source_files_properties(${JAVA_OUTPUT_JAR} PROPERTIES GENERATED TRUE) @@ -159,6 +162,9 @@ set(GRADLE_ARGS cmakeBuild -DcmakeBuildDir=${CMAKE_CURRENT_BINARY_DIR}) if(WIN32) set(GRADLE_ARGS ${GRADLE_ARGS} -Dorg.gradle.daemon=false) endif() +if(onnxruntime_USE_CUDA) + set(GRADLE_ARGS ${GRADLE_ARGS} -DUSE_CUDA=1) +endif() add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} ${GRADLE_ARGS} WORKING_DIRECTORY ${JAVA_ROOT}) if (CMAKE_SYSTEM_NAME STREQUAL "Android") add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} -b build-android.gradle -c settings-android.gradle build -DjniLibsDir=${ANDROID_PACKAGE_JNILIBS_DIR} -DbuildDir=${ANDROID_PACKAGE_OUTPUT_DIR} WORKING_DIRECTORY ${JAVA_ROOT}) diff --git a/java/build.gradle b/java/build.gradle index 4f1ee775bf..67d2e73f7e 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -15,6 +15,20 @@ allprojects { project.group = "com.microsoft.onnxruntime" version = rootProject.file('../VERSION_NUMBER').text.trim() +// cmake runs will inform us of the build directory of the current run +def cmakeBuildDir = System.properties['cmakeBuildDir'] +def useCUDA = System.properties['USE_CUDA'] +def cmakeJavaDir = "${cmakeBuildDir}/java" +def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib" +def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni" +def cmakeNativeTestDir = "${cmakeJavaDir}/native-test" +def cmakeBuildOutputDir = "${cmakeJavaDir}/build" + +def mavenUser = System.properties['mavenUser'] +def mavenPwd = System.properties['mavenPwd'] + +def mavenArtifactId = useCUDA != null ? project.name + "_gpu" : project.name + java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -29,7 +43,7 @@ jar { task sourcesJar(type: Jar, dependsOn: classes) { classifier = "sources" from sourceSets.main.allSource - into("META-INF/maven/$project.group/$project.name") { + into("META-INF/maven/$project.group/$mavenArtifactId") { from { generatePomFileForMavenPublication } rename ".*", "pom.xml" } @@ -39,7 +53,7 @@ task sourcesJar(type: Jar, dependsOn: classes) { task javadocJar(type: Jar, dependsOn: javadoc) { classifier = "javadoc" from javadoc.destinationDir - into("META-INF/maven/$project.group/$project.name") { + into("META-INF/maven/$project.group/$mavenArtifactId") { from { generatePomFileForMavenPublication } rename ".*", "pom.xml" } @@ -61,17 +75,6 @@ spotless { } } -// cmake runs will inform us of the build directory of the current run -def cmakeBuildDir = System.properties['cmakeBuildDir'] -def cmakeJavaDir = "${cmakeBuildDir}/java" -def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib" -def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni" -def cmakeNativeTestDir = "${cmakeJavaDir}/native-test" -def cmakeBuildOutputDir = "${cmakeJavaDir}/build" - -def mavenUser = System.properties['mavenUser'] -def mavenPwd = System.properties['mavenPwd'] - compileJava { options.compilerArgs += ["-h", "${project.buildDir}/headers/"] } @@ -98,7 +101,12 @@ if (cmakeBuildDir != null) { // Overwrite jar location task allJar(type: Jar) { - into("META-INF/maven/$project.group/$project.name") { + manifest { + attributes('Automatic-Module-Name': project.group, + 'Implementation-Title': 'onnxruntime', + 'Implementation-Version': project.version) + } + into("META-INF/maven/$project.group/$mavenArtifactId") { from { generatePomFileForMavenPublication } rename ".*", "pom.xml" } @@ -157,7 +165,7 @@ publishing { publications { maven(MavenPublication) { groupId = project.group - artifactId = project.name + artifactId = mavenArtifactId from components.java pom { diff --git a/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines-gpu.yml b/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines-gpu.yml index d6b28a71df..c4803cad79 100644 --- a/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines-gpu.yml +++ b/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines-gpu.yml @@ -153,16 +153,17 @@ jobs: - task: CmdLine@2 inputs: script: | + @echo on pushd onnxruntime-java-linux-x64-gpu jar uf $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64-gpu\testing.jar libcustom_op_library.so del /F /Q libcustom_op_library.so jar uf $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64-gpu\onnxruntime-$(OnnxRuntimeVersion).jar . popd pushd onnxruntime-java-win-x64-gpu - ren onnxruntime-$(OnnxRuntimeVersion).jar onnxruntime-gpu-$(OnnxRuntimeVersion).jar - ren onnxruntime-$(OnnxRuntimeVersion)-javadoc.jar onnxruntime-gpu-$(OnnxRuntimeVersion)-javadoc.jar - ren onnxruntime-$(OnnxRuntimeVersion)-sources.jar onnxruntime-gpu-$(OnnxRuntimeVersion)-sources.jar - ren onnxruntime-$(OnnxRuntimeVersion).pom onnxruntime-gpu-$(OnnxRuntimeVersion).pom + ren onnxruntime-$(OnnxRuntimeVersion).jar onnxruntime_gpu-$(OnnxRuntimeVersion).jar + ren onnxruntime-$(OnnxRuntimeVersion)-javadoc.jar onnxruntime_gpu-$(OnnxRuntimeVersion)-javadoc.jar + ren onnxruntime-$(OnnxRuntimeVersion)-sources.jar onnxruntime_gpu-$(OnnxRuntimeVersion)-sources.jar + ren onnxruntime-$(OnnxRuntimeVersion).pom onnxruntime_gpu_$(OnnxRuntimeVersion).pom popd workingDirectory: '$(Build.BinariesDirectory)\java-artifact' displayName: 'Create final GPU Jar' @@ -211,7 +212,7 @@ jobs: popd powershell -Command "Invoke-WebRequest https://oss.sonatype.org/service/local/repositories/releases/content/org/junit/platform/junit-platform-console-standalone/1.6.2/junit-platform-console-standalone-1.6.2.jar -OutFile junit-platform-console-standalone-1.6.2.jar" powershell -Command "Invoke-WebRequest https://oss.sonatype.org/service/local/repositories/google-releases/content/com/google/protobuf/protobuf-java/3.9.2/protobuf-java-3.9.2.jar -OutFile protobuf-java-3.9.2.jar" - java -DUSE_CUDA=1 -jar junit-platform-console-standalone-1.6.2.jar -cp .;.\test;protobuf-java-3.9.2.jar;onnxruntime-gpu-$(OnnxRuntimeVersion).jar --scan-class-path --fail-if-no-tests --disable-banner + java -DUSE_CUDA=1 -jar junit-platform-console-standalone-1.6.2.jar -cp .;.\test;protobuf-java-3.9.2.jar;onnxruntime_gpu-$(OnnxRuntimeVersion).jar --scan-class-path --fail-if-no-tests --disable-banner workingDirectory: '$(Build.BinariesDirectory)\final-jar' - job: Final_Jar_Testing_Linux diff --git a/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines.yml b/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines.yml index 3cdc47ae3c..84f6eb6ea7 100644 --- a/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines.yml +++ b/tools/ci_build/github/azure-pipelines/java-api-packaging-pipelines.yml @@ -216,6 +216,7 @@ jobs: - task: CmdLine@2 inputs: script: | + @echo on pushd onnxruntime-java-linux-x64 jar uf $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64\testing.jar libcustom_op_library.so del /F /Q libcustom_op_library.so diff --git a/tools/ci_build/github/azure-pipelines/templates/java-api-artifacts-package-and-publish-steps-windows.yml b/tools/ci_build/github/azure-pipelines/templates/java-api-artifacts-package-and-publish-steps-windows.yml index 2911722528..233e80b5e3 100644 --- a/tools/ci_build/github/azure-pipelines/templates/java-api-artifacts-package-and-publish-steps-windows.yml +++ b/tools/ci_build/github/azure-pipelines/templates/java-api-artifacts-package-and-publish-steps-windows.yml @@ -9,15 +9,19 @@ steps: - task: CmdLine@2 inputs: script: | - echo "Java version" - java --version + @echo on set NATIVE_FOLDER=$(Build.BinariesDirectory)\${{parameters.artifactName}}\stage\ai\onnxruntime\native\win-x64 mkdir %NATIVE_FOLDER% echo "Directories created" copy .\java\build\libs\*.jar $(Build.BinariesDirectory)\${{parameters.artifactName}} pushd $(Build.BinariesDirectory)\${{parameters.artifactName}} - jar xf onnxruntime-${{parameters.version}}.jar META-INF\maven\ai.onnxruntime\onnxruntime\pom.xml - move META-INF\maven\ai.onnxruntime\onnxruntime\pom.xml onnxruntime-${{parameters.version}}.pom + if ${{parameters.artifactName}} == onnxruntime-java-win-x64 ( + set artifact_id=onnxruntime + ) else ( + set artifact_id=onnxruntime_gpu + ) + jar xf onnxruntime-${{parameters.version}}.jar META-INF\maven\com.microsoft.onnxruntime\%artifact_id%\pom.xml + move META-INF\maven\com.microsoft.onnxruntime\%artifact_id%\pom.xml onnxruntime-${{parameters.version}}.pom rd /s /q META-INF popd copy .\${{parameters.buildConfig}}\onnxruntime.pdb %NATIVE_FOLDER% diff --git a/tools/ci_build/github/linux/java_linux_final_test.sh b/tools/ci_build/github/linux/java_linux_final_test.sh index c51394c1d3..d25af6a791 100755 --- a/tools/ci_build/github/linux/java_linux_final_test.sh +++ b/tools/ci_build/github/linux/java_linux_final_test.sh @@ -28,7 +28,7 @@ popd wget https://oss.sonatype.org/service/local/repositories/releases/content/org/junit/platform/junit-platform-console-standalone/1.6.2/junit-platform-console-standalone-1.6.2.jar -P ./ wget https://oss.sonatype.org/service/local/repositories/google-releases/content/com/google/protobuf/protobuf-java/3.9.2/protobuf-java-3.9.2.jar -P ./ -java -DUSE_CUDA=1 -jar ./junit-platform-console-standalone-1.6.2.jar -cp .:./test:./protobuf-java-3.9.2.jar:./onnxruntime-gpu-${VERSION_NUMBER}.jar --scan-class-path --fail-if-no-tests --disable-banner +java -DUSE_CUDA=1 -jar ./junit-platform-console-standalone-1.6.2.jar -cp .:./test:./protobuf-java-3.9.2.jar:./onnxruntime_gpu-${VERSION_NUMBER}.jar --scan-class-path --fail-if-no-tests --disable-banner EXIT_CODE=$?