onnxruntime
298 строк · 8.4 Кб
1plugins {
2id 'java-library'
3id 'maven-publish'
4id 'signing'
5id 'jacoco'
6id "com.diffplug.spotless" version "6.25.0"
7id "net.linguica.maven-settings" version "0.5"
8}
9
10allprojects {
11repositories {
12mavenCentral()
13}
14}
15
16project.group = "com.microsoft.onnxruntime"
17version = rootProject.file('../VERSION_NUMBER').text.trim()
18
19// cmake runs will inform us of the build directory of the current run
20def cmakeBuildDir = System.properties['cmakeBuildDir']
21def useCUDA = System.properties['USE_CUDA']
22def useROCM = System.properties['USE_ROCM']
23
24def adoArtifact = project.findProperty('adoArtifact')
25def adoAccessToken = project.findProperty('adoAccessToken')
26// Only publish to ADO feed if all two properties are set
27def publishToAdo = adoArtifact != null && adoAccessToken != null
28
29boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1"
30def cmakeJavaDir = "${cmakeBuildDir}/java"
31def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
32def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni"
33def cmakeNativeTestDir = "${cmakeJavaDir}/native-test"
34def cmakeBuildOutputDir = "${cmakeJavaDir}/build"
35
36def mavenUser = System.properties['mavenUser']
37def mavenPwd = System.properties['mavenPwd']
38
39def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name
40def mavenArtifactId = (useCUDA == null && useROCM == null) ? tmpArtifactId : tmpArtifactId + "_gpu"
41
42def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network Exchange) models.'
43def trainingDescription = 'ONNX Runtime Training is a training and inference package for ONNX ' +
44'(Open Neural Network Exchange) models. This package is targeted for Learning on The Edge aka On-Device Training ' +
45'See https://github.com/microsoft/onnxruntime-training-examples/tree/master/on_device_training for more details.'
46
47// We need to have a custom settings.xml so codeql can bypass the need for settings.security.xml
48mavenSettings {
49userSettingsFileName = "${projectDir}/settings.xml"
50}
51
52java {
53sourceCompatibility = JavaVersion.VERSION_1_8
54targetCompatibility = JavaVersion.VERSION_1_8
55}
56
57// This jar tasks serves as a CMAKE signaling
58// mechanism. The jar will be overwritten by allJar task
59jar {
60}
61
62// Add explicit sources jar with pom file.
63tasks.register('sourcesJar', Jar) {
64dependsOn classes
65archiveClassifier = "sources"
66from sourceSets.main.allSource
67into("META-INF/maven/$project.group/$mavenArtifactId") {
68from { generatePomFileForMavenPublication }
69rename ".*", "pom.xml"
70}
71}
72
73// Add explicit javadoc jar with pom file
74tasks.register('javadocJar', Jar) {
75dependsOn javadoc
76archiveClassifier = "javadoc"
77from javadoc.destinationDir
78into("META-INF/maven/$project.group/$mavenArtifactId") {
79from { generatePomFileForMavenPublication }
80rename ".*", "pom.xml"
81}
82}
83
84spotless {
85java {
86removeUnusedImports()
87googleJavaFormat()
88targetExclude "src/test/java/ai/onnxruntime/OnnxMl.java"
89}
90format 'gradle', {
91target '**/*.gradle'
92trimTrailingWhitespace()
93indentWithTabs()
94}
95}
96
97compileJava {
98dependsOn spotlessJava
99options.compilerArgs += ["-h", "${layout.buildDirectory.get().toString()}/headers/"]
100if (!JavaVersion.current().isJava8()) {
101// Ensures only methods present in Java 8 are used
102options.compilerArgs.addAll(['--release', '8'])
103// Gradle versions before 6.6 require that these flags are unset when using "-release"
104java.sourceCompatibility = null
105java.targetCompatibility = null
106}
107}
108
109compileTestJava {
110if (!JavaVersion.current().isJava8()) {
111// Ensures only methods present in Java 8 are used
112options.compilerArgs.addAll(['--release', '8'])
113// Gradle versions before 6.6 require that these flags are unset when using "-release"
114java.sourceCompatibility = null
115java.targetCompatibility = null
116}
117}
118
119sourceSets.main.java {
120srcDirs = ['src/main/java', 'src/main/jvm']
121}
122
123sourceSets.test {
124// add test resource files
125resources.srcDirs += [
126"${rootProject.projectDir}/../csharp/testdata",
127"${rootProject.projectDir}/../onnxruntime/test/testdata",
128"${rootProject.projectDir}/../onnxruntime/test/testdata/training_api",
129"${rootProject.projectDir}/../java/testdata"
130]
131if (cmakeBuildDir != null) {
132// add compiled native libs
133resources.srcDirs += [
134cmakeNativeLibDir,
135cmakeNativeJniDir,
136cmakeNativeTestDir
137]
138}
139}
140
141if (cmakeBuildDir != null) {
142// generate tasks to be called from cmake
143
144// Overwrite jar location
145tasks.register('allJar', Jar) {
146manifest {
147attributes('Automatic-Module-Name': project.group,
148'Implementation-Title': 'onnxruntime',
149'Implementation-Version': project.version)
150}
151into("META-INF/maven/$project.group/$mavenArtifactId") {
152from { generatePomFileForMavenPublication }
153rename ".*", "pom.xml"
154}
155from sourceSets.main.output
156from cmakeNativeJniDir
157from cmakeNativeLibDir
158}
159
160tasks.register('cmakeBuild', Copy) {
161from layout.buildDirectory.get()
162include 'libs/**'
163include 'docs/**'
164into cmakeBuildOutputDir
165dependsOn(allJar, sourcesJar, javadocJar, javadoc)
166}
167
168tasks.register('cmakeCheck', Copy) {
169group = 'verification'
170from layout.buildDirectory.get()
171include 'reports/**'
172into cmakeBuildOutputDir
173dependsOn(check)
174}
175} else {
176println "cmakeBuildDir is not set. Skipping cmake tasks."
177}
178
179dependencies {
180testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
181testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
182testImplementation 'com.google.protobuf:protobuf-java:3.21.7'
183}
184
185processTestResources {
186duplicatesStrategy(DuplicatesStrategy.INCLUDE) // allows duplicates in the test resources
187}
188
189test {
190java {
191dependsOn spotlessJava
192}
193if (System.getProperty("JAVA_FULL_TEST") != null) {
194// Forces each test class to be run in a separate JVM,
195// which is necessary for testing the environment thread pool which is ignored if full test is not set.
196forkEvery 1
197}
198useJUnitPlatform()
199if (cmakeBuildDir != null) {
200workingDir cmakeBuildDir
201}
202systemProperties System.getProperties().subMap(['USE_CUDA', 'USE_ROCM', 'USE_TENSORRT', 'USE_DNNL', 'USE_OPENVINO', 'USE_COREML', 'USE_DML', 'JAVA_FULL_TEST', 'ENABLE_TRAINING_APIS'])
203testLogging {
204events "passed", "skipped", "failed"
205showStandardStreams = true
206showStackTraces = true
207exceptionFormat = "full"
208}
209}
210
211jacocoTestReport {
212reports {
213xml.required = true
214csv.required = true
215html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
216}
217}
218
219publishing {
220publications {
221maven(MavenPublication) {
222groupId = project.group
223if(publishToAdo) {
224artifactId = 'onnxruntime_gpu'
225artifact (adoArtifact)
226} else {
227artifactId = mavenArtifactId
228from components.java
229}
230version = project.version
231pom {
232name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
233description = enableTrainingApis ? trainingDescription : defaultDescription
234url = 'https://microsoft.github.io/onnxruntime/'
235licenses {
236license {
237name = 'MIT License'
238url = 'https://opensource.org/licenses/MIT'
239}
240}
241organization {
242name = 'Microsoft'
243url = 'https://www.microsoft.com'
244}
245scm {
246connection = 'scm:git:git://github.com:microsoft/onnxruntime.git'
247developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime.git'
248url = 'https://github.com/microsoft/onnxruntime'
249}
250developers {
251developer {
252id = 'onnxruntime'
253name = 'ONNX Runtime'
254email = 'onnxruntime@microsoft.com'
255}
256}
257}
258}
259}
260repositories {
261if (publishToAdo) {
262maven {
263url "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/${System.getenv('ADOFeedName')}/maven/v1"
264name System.getenv('ADOFeedName')
265authentication {
266basic(BasicAuthentication)
267}
268credentials {
269username 'aiinfra'
270password "${project.findProperty('adoAccessToken')}"
271}
272}
273} else {
274maven {
275url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
276credentials {
277username mavenUser
278password mavenPwd
279}
280}
281}
282}
283}
284// Generates a task signMavenPublication that will
285// build all artifacts.
286signing {
287// Queries env vars:
288// ORG_GRADLE_PROJECT_signingKey
289// ORG_GRADLE_PROJECT_signingPassword but can be changed to properties
290def signingKey = findProperty("signingKey")
291def signingPassword = findProperty("signingPassword")
292// Skip signing if no key is provided
293if (signingKey != null && signingPassword != null) {
294useInMemoryPgpKeys(signingKey, signingPassword)
295sign publishing.publications.maven
296sign publishing.publications.mavenAdo
297}
298}
299