### Description
Bump spotless and the Gradle wrapper to 6.25.0 and 8.6 respectively to
allow compiling ORT on Java 21. The build still targets Java 8.

I'm not sure if there will be CI changes necessary to use this PR,
specifically for the Gradle version as I don't know if that is cached
somewhere earlier in the CI build process.

The new Gradle version adds a warning that using `--source` and
`--target` to select the Java language version is obsolete which is
annoying, we can fix it if we decide to only allow building on newer
versions of Java, while still supporting running on Java 8.

### Motivation and Context
Java 21 is the latest LTS release of Java and ORT should be able to
build on it.
This commit is contained in:
Adam Pocock 2024-03-28 18:51:22 -04:00 коммит произвёл GitHub
Родитель f7b52d2e3e
Коммит 2f82400b13
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 41 добавлений и 17 удалений

Просмотреть файл

@ -14,7 +14,7 @@ Use the main project's [build instructions](https://www.onnxruntime.ai/docs/how-
#### Requirements
JDK version 8 or later is required.
Java 11 or later is required to build the library. The compiled jar file will run on Java 8 or later.
The [Gradle](https://gradle.org/) build system is used here to manage the Java project's dependency management, compilation, testing, and assembly.
In particular, the Gradle [wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) at `java/gradlew[.bat]` is used, locking the Gradle version to the one specified in the `java/gradle/wrapper/gradle-wrapper.properties` configuration.
@ -35,6 +35,7 @@ This allows the CMake system to ensure all of the C/C++ compilation is achieved
The Java build depends on C/C++ onnxruntime shared library and a C JNI shared library (source located in the `src/main/native` directory).
The JNI shared library is the glue that allows for Java to call functions in onnxruntime shared library.
Given the fact that CMake injects native dependencies during CMake builds, some gradle tasks (primarily, `build`, `test`, and `check`) may fail.
To run the Java build independently of CMake supply `-DcmakeBuildDir=<path-to-onnx-runtime-build-dir>`, though this will only succeed after an initial build of the native libraries has completed.
When running the build script, CMake will compile the `onnxruntime` target and the JNI glue `onnxruntime4j_jni` target and expose the resulting libraries in a place where Gradle can ingest them.
Upon successful compilation of those targets, a special Gradle task to build will be executed. The results will be placed in the output directory stated above.
@ -61,4 +62,4 @@ Then the corresponding C files in `./src/main/native/ai_onnxruntime*.c` may be u
### Dependencies
The Java API does not have any runtime or compile dependencies currently.
The Java API does not have any runtime or compile dependencies.

Просмотреть файл

@ -3,7 +3,7 @@ plugins {
id 'maven-publish'
id 'signing'
id 'jacoco'
id "com.diffplug.spotless" version "6.13.0"
id "com.diffplug.spotless" version "6.25.0"
}
allprojects {

Двоичные данные
java/gradle/wrapper/gradle-wrapper.jar поставляемый

Двоичный файл не отображается.

Просмотреть файл

@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=1b6b558be93f29438d3df94b7dfee02e794b94d9aca4611a92cdb79b6b88e909
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionSha256Sum=9631d53cf3e74bfa726893aee1f8994fee4e060c401335946dba2156f440f24c
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

29
java/gradlew поставляемый
Просмотреть файл

@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@ -133,10 +131,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \

Просмотреть файл

@ -45,8 +45,10 @@ public enum OnnxJavaType {
/** The native value of the enum. */
public final int value;
/** The Java side type used as the carrier. */
public final Class<?> clazz;
/** The number of bytes used by a single value of this type. */
public final int size;

Просмотреть файл

@ -39,6 +39,7 @@ public class OnnxMap implements OnnxValue {
FLOAT(3),
/** A 64-bit floating point value. */
DOUBLE(4);
/** The native enum value. */
final int value;

Просмотреть файл

@ -54,19 +54,25 @@ final class OnnxRuntime {
/** The short name of the ONNX runtime shared library */
static final String ONNXRUNTIME_LIBRARY_NAME = "onnxruntime";
/** The short name of the ONNX runtime JNI shared library */
static final String ONNXRUNTIME_JNI_LIBRARY_NAME = "onnxruntime4j_jni";
/** The short name of the ONNX runtime shared provider library */
static final String ONNXRUNTIME_LIBRARY_SHARED_NAME = "onnxruntime_providers_shared";
/** The short name of the ONNX runtime CUDA provider library */
static final String ONNXRUNTIME_LIBRARY_CUDA_NAME = "onnxruntime_providers_cuda";
/** The short name of the ONNX runtime ROCM provider library */
static final String ONNXRUNTIME_LIBRARY_ROCM_NAME = "onnxruntime_providers_rocm";
/** The short name of the ONNX runtime DNNL provider library */
static final String ONNXRUNTIME_LIBRARY_DNNL_NAME = "onnxruntime_providers_dnnl";
/** The short name of the ONNX runtime OpenVINO provider library */
static final String ONNXRUNTIME_LIBRARY_OPENVINO_NAME = "onnxruntime_providers_openvino";
/** The short name of the ONNX runtime TensorRT provider library */
static final String ONNXRUNTIME_LIBRARY_TENSORRT_NAME = "onnxruntime_providers_tensorrt";

Просмотреть файл

@ -637,6 +637,7 @@ public final class OnnxSparseTensor extends OnnxTensorLike {
/** The buffer holding the indices. */
final T indices;
/** The buffer holding the values. */
final Buffer values;

Просмотреть файл

@ -30,6 +30,7 @@ import java.util.regex.Pattern;
public class ScoreMNIST {
private static final Logger logger = Logger.getLogger(ScoreMNIST.class.getName());
/** Pattern for splitting libsvm format files. */
private static final Pattern splitPattern = Pattern.compile("\\s+");

Просмотреть файл

@ -52,6 +52,12 @@ jobs:
inputs:
versionSpec: '18.x'
- task: JavaToolInstaller@0
inputs:
versionSpec: "11"
jdkArchitectureOption: "x64"
jdkSourceOption: 'PreInstalled'
- template: set-version-number-variables-step.yml
- template: use-xcode-version.yml