2020-02-19 02:41:49 +03:00
|
|
|
plugins {
|
2020-05-13 01:31:20 +03:00
|
|
|
id 'java-library'
|
2020-04-21 12:28:15 +03:00
|
|
|
id 'maven-publish'
|
2020-05-13 01:31:20 +03:00
|
|
|
id 'signing'
|
|
|
|
id 'jacoco'
|
2024-03-29 01:51:22 +03:00
|
|
|
id "com.diffplug.spotless" version "6.25.0"
|
2024-05-30 02:24:23 +03:00
|
|
|
id "net.linguica.maven-settings" version "0.5"
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 02:44:33 +03:00
|
|
|
project.group = "com.microsoft.onnxruntime"
|
2020-05-13 01:31:20 +03:00
|
|
|
version = rootProject.file('../VERSION_NUMBER').text.trim()
|
|
|
|
|
2020-06-10 21:15:48 +03:00
|
|
|
// cmake runs will inform us of the build directory of the current run
|
|
|
|
def cmakeBuildDir = System.properties['cmakeBuildDir']
|
|
|
|
def useCUDA = System.properties['USE_CUDA']
|
2021-10-15 01:15:51 +03:00
|
|
|
def useROCM = System.properties['USE_ROCM']
|
2024-05-30 02:24:23 +03:00
|
|
|
|
|
|
|
def adoArtifact = project.findProperty('adoArtifact')
|
|
|
|
def adoAccessToken = project.findProperty('adoAccessToken')
|
|
|
|
// Only publish to ADO feed if all two properties are set
|
|
|
|
def publishToAdo = adoArtifact != null && adoAccessToken != null
|
|
|
|
|
2023-05-01 22:59:56 +03:00
|
|
|
boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1"
|
2020-06-10 21:15:48 +03:00
|
|
|
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']
|
|
|
|
|
2023-05-01 22:59:56 +03:00
|
|
|
def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name
|
2023-03-08 21:01:08 +03:00
|
|
|
def mavenArtifactId = (useCUDA == null && useROCM == null) ? tmpArtifactId : tmpArtifactId + "_gpu"
|
2020-06-10 21:15:48 +03:00
|
|
|
|
2023-05-01 22:59:56 +03:00
|
|
|
def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network Exchange) models.'
|
|
|
|
def trainingDescription = 'ONNX Runtime Training is a training and inference package for ONNX ' +
|
|
|
|
'(Open Neural Network Exchange) models. This package is targeted for Learning on The Edge aka On-Device Training ' +
|
|
|
|
'See https://github.com/microsoft/onnxruntime-training-examples/tree/master/on_device_training for more details.'
|
|
|
|
|
2024-05-30 02:24:23 +03:00
|
|
|
// We need to have a custom settings.xml so codeql can bypass the need for settings.security.xml
|
|
|
|
mavenSettings {
|
|
|
|
userSettingsFileName = "${projectDir}/settings.xml"
|
|
|
|
}
|
|
|
|
|
2020-02-19 02:41:49 +03:00
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
2020-04-21 12:28:15 +03:00
|
|
|
}
|
|
|
|
|
2024-07-22 23:37:32 +03:00
|
|
|
// This jar tasks serves as a CMAKE signaling
|
2020-05-13 01:31:20 +03:00
|
|
|
// mechanism. The jar will be overwritten by allJar task
|
2020-04-21 12:28:15 +03:00
|
|
|
jar {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add explicit sources jar with pom file.
|
2024-06-07 21:08:52 +03:00
|
|
|
tasks.register('sourcesJar', Jar) {
|
|
|
|
dependsOn classes
|
2023-02-20 06:19:49 +03:00
|
|
|
archiveClassifier = "sources"
|
2020-04-21 12:28:15 +03:00
|
|
|
from sourceSets.main.allSource
|
2020-06-10 21:15:48 +03:00
|
|
|
into("META-INF/maven/$project.group/$mavenArtifactId") {
|
2020-04-21 12:28:15 +03:00
|
|
|
from { generatePomFileForMavenPublication }
|
|
|
|
rename ".*", "pom.xml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add explicit javadoc jar with pom file
|
2024-06-07 21:08:52 +03:00
|
|
|
tasks.register('javadocJar', Jar) {
|
|
|
|
dependsOn javadoc
|
2023-02-20 06:19:49 +03:00
|
|
|
archiveClassifier = "javadoc"
|
2020-04-21 12:28:15 +03:00
|
|
|
from javadoc.destinationDir
|
2020-06-10 21:15:48 +03:00
|
|
|
into("META-INF/maven/$project.group/$mavenArtifactId") {
|
2020-04-21 12:28:15 +03:00
|
|
|
from { generatePomFileForMavenPublication }
|
|
|
|
rename ".*", "pom.xml"
|
|
|
|
}
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
spotless {
|
2020-02-19 04:06:10 +03:00
|
|
|
java {
|
|
|
|
removeUnusedImports()
|
|
|
|
googleJavaFormat()
|
2023-03-08 21:01:08 +03:00
|
|
|
targetExclude "src/test/java/ai/onnxruntime/OnnxMl.java"
|
2020-02-19 04:06:10 +03:00
|
|
|
}
|
2020-02-19 02:41:49 +03:00
|
|
|
format 'gradle', {
|
|
|
|
target '**/*.gradle'
|
|
|
|
trimTrailingWhitespace()
|
|
|
|
indentWithTabs()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compileJava {
|
2021-01-28 00:25:22 +03:00
|
|
|
dependsOn spotlessJava
|
2024-06-07 21:08:52 +03:00
|
|
|
options.compilerArgs += ["-h", "${layout.buildDirectory.get().toString()}/headers/"]
|
2021-02-05 22:55:34 +03:00
|
|
|
if (!JavaVersion.current().isJava8()) {
|
|
|
|
// Ensures only methods present in Java 8 are used
|
|
|
|
options.compilerArgs.addAll(['--release', '8'])
|
|
|
|
// Gradle versions before 6.6 require that these flags are unset when using "-release"
|
|
|
|
java.sourceCompatibility = null
|
|
|
|
java.targetCompatibility = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compileTestJava {
|
|
|
|
if (!JavaVersion.current().isJava8()) {
|
|
|
|
// Ensures only methods present in Java 8 are used
|
|
|
|
options.compilerArgs.addAll(['--release', '8'])
|
|
|
|
// Gradle versions before 6.6 require that these flags are unset when using "-release"
|
|
|
|
java.sourceCompatibility = null
|
|
|
|
java.targetCompatibility = null
|
|
|
|
}
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 22:31:32 +03:00
|
|
|
sourceSets.main.java {
|
|
|
|
srcDirs = ['src/main/java', 'src/main/jvm']
|
|
|
|
}
|
|
|
|
|
2020-02-19 02:41:49 +03:00
|
|
|
sourceSets.test {
|
|
|
|
// add test resource files
|
|
|
|
resources.srcDirs += [
|
|
|
|
"${rootProject.projectDir}/../csharp/testdata",
|
2020-02-22 00:13:02 +03:00
|
|
|
"${rootProject.projectDir}/../onnxruntime/test/testdata",
|
2023-03-08 21:01:08 +03:00
|
|
|
"${rootProject.projectDir}/../onnxruntime/test/testdata/training_api",
|
2020-02-22 00:13:02 +03:00
|
|
|
"${rootProject.projectDir}/../java/testdata"
|
2020-02-19 02:41:49 +03:00
|
|
|
]
|
|
|
|
if (cmakeBuildDir != null) {
|
|
|
|
// add compiled native libs
|
|
|
|
resources.srcDirs += [
|
|
|
|
cmakeNativeLibDir,
|
2020-05-06 11:19:46 +03:00
|
|
|
cmakeNativeJniDir,
|
|
|
|
cmakeNativeTestDir
|
2020-02-19 02:41:49 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmakeBuildDir != null) {
|
|
|
|
// generate tasks to be called from cmake
|
|
|
|
|
2020-05-13 01:31:20 +03:00
|
|
|
// Overwrite jar location
|
2024-06-07 21:08:52 +03:00
|
|
|
tasks.register('allJar', Jar) {
|
2020-06-10 21:15:48 +03:00
|
|
|
manifest {
|
|
|
|
attributes('Automatic-Module-Name': project.group,
|
|
|
|
'Implementation-Title': 'onnxruntime',
|
|
|
|
'Implementation-Version': project.version)
|
|
|
|
}
|
|
|
|
into("META-INF/maven/$project.group/$mavenArtifactId") {
|
2020-04-21 12:28:15 +03:00
|
|
|
from { generatePomFileForMavenPublication }
|
|
|
|
rename ".*", "pom.xml"
|
|
|
|
}
|
2020-02-19 02:41:49 +03:00
|
|
|
from sourceSets.main.output
|
|
|
|
from cmakeNativeJniDir
|
|
|
|
from cmakeNativeLibDir
|
|
|
|
}
|
|
|
|
|
2024-06-07 21:08:52 +03:00
|
|
|
tasks.register('cmakeBuild', Copy) {
|
|
|
|
from layout.buildDirectory.get()
|
2020-02-19 02:41:49 +03:00
|
|
|
include 'libs/**'
|
|
|
|
include 'docs/**'
|
|
|
|
into cmakeBuildOutputDir
|
2024-06-07 21:08:52 +03:00
|
|
|
dependsOn(allJar, sourcesJar, javadocJar, javadoc)
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
|
2024-06-07 21:08:52 +03:00
|
|
|
tasks.register('cmakeCheck', Copy) {
|
2024-06-25 02:46:21 +03:00
|
|
|
group = 'verification'
|
2024-06-07 21:08:52 +03:00
|
|
|
from layout.buildDirectory.get()
|
2020-02-19 02:41:49 +03:00
|
|
|
include 'reports/**'
|
|
|
|
into cmakeBuildOutputDir
|
2024-06-07 21:08:52 +03:00
|
|
|
dependsOn(check)
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
2024-06-25 02:46:21 +03:00
|
|
|
} else {
|
|
|
|
println "cmakeBuildDir is not set. Skipping cmake tasks."
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2023-03-08 21:01:08 +03:00
|
|
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
|
|
|
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
|
2022-11-18 02:04:42 +03:00
|
|
|
testImplementation 'com.google.protobuf:protobuf-java:3.21.7'
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
|
2021-01-28 00:25:22 +03:00
|
|
|
processTestResources {
|
|
|
|
duplicatesStrategy(DuplicatesStrategy.INCLUDE) // allows duplicates in the test resources
|
|
|
|
}
|
|
|
|
|
2020-02-19 02:41:49 +03:00
|
|
|
test {
|
2021-01-28 00:25:22 +03:00
|
|
|
java {
|
|
|
|
dependsOn spotlessJava
|
|
|
|
}
|
2022-03-09 09:19:37 +03:00
|
|
|
if (System.getProperty("JAVA_FULL_TEST") != null) {
|
|
|
|
// Forces each test class to be run in a separate JVM,
|
|
|
|
// which is necessary for testing the environment thread pool which is ignored if full test is not set.
|
|
|
|
forkEvery 1
|
|
|
|
}
|
2020-02-19 02:41:49 +03:00
|
|
|
useJUnitPlatform()
|
2020-05-06 11:19:46 +03:00
|
|
|
if (cmakeBuildDir != null) {
|
|
|
|
workingDir cmakeBuildDir
|
|
|
|
}
|
2024-10-01 20:18:04 +03:00
|
|
|
systemProperties System.getProperties().subMap([
|
|
|
|
'ENABLE_TRAINING_APIS',
|
|
|
|
'JAVA_FULL_TEST',
|
|
|
|
'USE_COREML',
|
|
|
|
'USE_CUDA',
|
|
|
|
'USE_DML',
|
|
|
|
'USE_DNNL',
|
|
|
|
'USE_OPENVINO',
|
|
|
|
'USE_ROCM',
|
|
|
|
'USE_TENSORRT',
|
|
|
|
'USE_QNN',
|
|
|
|
'USE_XNNPACK',
|
|
|
|
])
|
2020-02-19 02:41:49 +03:00
|
|
|
testLogging {
|
|
|
|
events "passed", "skipped", "failed"
|
2020-04-21 12:28:15 +03:00
|
|
|
showStandardStreams = true
|
2022-01-10 20:42:46 +03:00
|
|
|
showStackTraces = true
|
|
|
|
exceptionFormat = "full"
|
2020-02-19 02:41:49 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-16 12:29:23 +03:00
|
|
|
|
|
|
|
jacocoTestReport {
|
|
|
|
reports {
|
2023-02-20 06:19:49 +03:00
|
|
|
xml.required = true
|
|
|
|
csv.required = true
|
2024-06-07 21:08:52 +03:00
|
|
|
html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
|
2020-04-16 12:29:23 +03:00
|
|
|
}
|
|
|
|
}
|
2020-04-21 12:28:15 +03:00
|
|
|
|
|
|
|
publishing {
|
|
|
|
publications {
|
|
|
|
maven(MavenPublication) {
|
|
|
|
groupId = project.group
|
2024-05-30 02:24:23 +03:00
|
|
|
if(publishToAdo) {
|
|
|
|
artifactId = 'onnxruntime_gpu'
|
|
|
|
artifact (adoArtifact)
|
|
|
|
} else {
|
|
|
|
artifactId = mavenArtifactId
|
|
|
|
from components.java
|
|
|
|
}
|
2024-06-07 21:08:52 +03:00
|
|
|
version = project.version
|
2020-04-21 12:28:15 +03:00
|
|
|
pom {
|
2023-05-01 22:59:56 +03:00
|
|
|
name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
|
|
|
|
description = enableTrainingApis ? trainingDescription : defaultDescription
|
2020-04-21 12:28:15 +03:00
|
|
|
url = 'https://microsoft.github.io/onnxruntime/'
|
|
|
|
licenses {
|
|
|
|
license {
|
|
|
|
name = 'MIT License'
|
|
|
|
url = 'https://opensource.org/licenses/MIT'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
organization {
|
|
|
|
name = 'Microsoft'
|
2023-03-08 21:01:08 +03:00
|
|
|
url = 'https://www.microsoft.com'
|
2020-04-21 12:28:15 +03:00
|
|
|
}
|
|
|
|
scm {
|
|
|
|
connection = 'scm:git:git://github.com:microsoft/onnxruntime.git'
|
|
|
|
developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime.git'
|
2023-03-08 21:01:08 +03:00
|
|
|
url = 'https://github.com/microsoft/onnxruntime'
|
2020-04-21 12:28:15 +03:00
|
|
|
}
|
2020-05-13 01:31:20 +03:00
|
|
|
developers {
|
|
|
|
developer {
|
|
|
|
id = 'onnxruntime'
|
|
|
|
name = 'ONNX Runtime'
|
|
|
|
email = 'onnxruntime@microsoft.com'
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 12:28:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 01:31:20 +03:00
|
|
|
repositories {
|
2024-05-30 02:24:23 +03:00
|
|
|
if (publishToAdo) {
|
|
|
|
maven {
|
|
|
|
url "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/${System.getenv('ADOFeedName')}/maven/v1"
|
|
|
|
name System.getenv('ADOFeedName')
|
|
|
|
authentication {
|
|
|
|
basic(BasicAuthentication)
|
|
|
|
}
|
|
|
|
credentials {
|
|
|
|
username 'aiinfra'
|
|
|
|
password "${project.findProperty('adoAccessToken')}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
maven {
|
|
|
|
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
|
|
|
|
credentials {
|
|
|
|
username mavenUser
|
|
|
|
password mavenPwd
|
|
|
|
}
|
2020-05-13 01:31:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Generates a task signMavenPublication that will
|
|
|
|
// build all artifacts.
|
|
|
|
signing {
|
|
|
|
// Queries env vars:
|
|
|
|
// ORG_GRADLE_PROJECT_signingKey
|
|
|
|
// ORG_GRADLE_PROJECT_signingPassword but can be changed to properties
|
2024-05-30 02:24:23 +03:00
|
|
|
def signingKey = findProperty("signingKey")
|
|
|
|
def signingPassword = findProperty("signingPassword")
|
|
|
|
// Skip signing if no key is provided
|
|
|
|
if (signingKey != null && signingPassword != null) {
|
|
|
|
useInMemoryPgpKeys(signingKey, signingPassword)
|
|
|
|
sign publishing.publications.maven
|
|
|
|
sign publishing.publications.mavenAdo
|
|
|
|
}
|
2020-04-21 12:28:15 +03:00
|
|
|
}
|