onnxruntime

Форк
0
/
build.gradle 
298 строк · 8.4 Кб
1
plugins {
2
	id 'java-library'
3
	id 'maven-publish'
4
	id 'signing'
5
	id 'jacoco'
6
	id "com.diffplug.spotless" version "6.25.0"
7
	id "net.linguica.maven-settings" version "0.5"
8
}
9

10
allprojects {
11
	repositories {
12
		mavenCentral()
13
	}
14
}
15

16
project.group = "com.microsoft.onnxruntime"
17
version = rootProject.file('../VERSION_NUMBER').text.trim()
18

19
// cmake runs will inform us of the build directory of the current run
20
def cmakeBuildDir = System.properties['cmakeBuildDir']
21
def useCUDA = System.properties['USE_CUDA']
22
def useROCM = System.properties['USE_ROCM']
23

24
def adoArtifact = project.findProperty('adoArtifact')
25
def adoAccessToken = project.findProperty('adoAccessToken')
26
// Only publish to ADO feed if all two properties are set
27
def publishToAdo = adoArtifact != null && adoAccessToken != null
28

29
boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1"
30
def cmakeJavaDir = "${cmakeBuildDir}/java"
31
def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
32
def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni"
33
def cmakeNativeTestDir = "${cmakeJavaDir}/native-test"
34
def cmakeBuildOutputDir = "${cmakeJavaDir}/build"
35

36
def mavenUser = System.properties['mavenUser']
37
def mavenPwd = System.properties['mavenPwd']
38

39
def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name
40
def mavenArtifactId = (useCUDA == null && useROCM == null) ? tmpArtifactId : tmpArtifactId + "_gpu"
41

42
def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network Exchange) models.'
43
def 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
48
mavenSettings {
49
	userSettingsFileName = "${projectDir}/settings.xml"
50
}
51

52
java {
53
	sourceCompatibility = JavaVersion.VERSION_1_8
54
	targetCompatibility = 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
59
jar {
60
}
61

62
// Add explicit sources jar with pom file.
63
tasks.register('sourcesJar', Jar) {
64
	dependsOn classes
65
	archiveClassifier = "sources"
66
	from sourceSets.main.allSource
67
	into("META-INF/maven/$project.group/$mavenArtifactId") {
68
		from { generatePomFileForMavenPublication }
69
		rename ".*", "pom.xml"
70
	}
71
}
72

73
// Add explicit javadoc jar with pom file
74
tasks.register('javadocJar', Jar) {
75
	dependsOn javadoc
76
	archiveClassifier = "javadoc"
77
	from javadoc.destinationDir
78
	into("META-INF/maven/$project.group/$mavenArtifactId") {
79
		from { generatePomFileForMavenPublication }
80
		rename ".*", "pom.xml"
81
	}
82
}
83

84
spotless {
85
	java {
86
		removeUnusedImports()
87
		googleJavaFormat()
88
		targetExclude "src/test/java/ai/onnxruntime/OnnxMl.java"
89
	}
90
	format 'gradle', {
91
		target '**/*.gradle'
92
		trimTrailingWhitespace()
93
		indentWithTabs()
94
	}
95
}
96

97
compileJava {
98
	dependsOn spotlessJava
99
	options.compilerArgs += ["-h", "${layout.buildDirectory.get().toString()}/headers/"]
100
	if (!JavaVersion.current().isJava8()) {
101
		// Ensures only methods present in Java 8 are used
102
		options.compilerArgs.addAll(['--release', '8'])
103
		// Gradle versions before 6.6 require that these flags are unset when using "-release"
104
		java.sourceCompatibility = null
105
		java.targetCompatibility = null
106
	}
107
}
108

109
compileTestJava {
110
	if (!JavaVersion.current().isJava8()) {
111
		// Ensures only methods present in Java 8 are used
112
		options.compilerArgs.addAll(['--release', '8'])
113
		// Gradle versions before 6.6 require that these flags are unset when using "-release"
114
		java.sourceCompatibility = null
115
		java.targetCompatibility = null
116
	}
117
}
118

119
sourceSets.main.java {
120
	srcDirs = ['src/main/java', 'src/main/jvm']
121
}
122

123
sourceSets.test {
124
	// add test resource files
125
	resources.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
	]
131
	if (cmakeBuildDir != null) {
132
		// add compiled native libs
133
		resources.srcDirs += [
134
			cmakeNativeLibDir,
135
			cmakeNativeJniDir,
136
			cmakeNativeTestDir
137
		]
138
	}
139
}
140

141
if (cmakeBuildDir != null) {
142
	// generate tasks to be called from cmake
143

144
	// Overwrite jar location
145
	tasks.register('allJar', Jar) {
146
		manifest {
147
			attributes('Automatic-Module-Name': project.group,
148
					'Implementation-Title': 'onnxruntime',
149
					'Implementation-Version': project.version)
150
		}
151
		into("META-INF/maven/$project.group/$mavenArtifactId") {
152
			from { generatePomFileForMavenPublication }
153
			rename ".*", "pom.xml"
154
		}
155
		from sourceSets.main.output
156
		from cmakeNativeJniDir
157
		from cmakeNativeLibDir
158
	}
159

160
	tasks.register('cmakeBuild', Copy) {
161
		from layout.buildDirectory.get()
162
		include 'libs/**'
163
		include 'docs/**'
164
		into cmakeBuildOutputDir
165
		dependsOn(allJar, sourcesJar, javadocJar, javadoc)
166
	}
167

168
	tasks.register('cmakeCheck', Copy) {
169
		group = 'verification'
170
		from layout.buildDirectory.get()
171
		include 'reports/**'
172
		into cmakeBuildOutputDir
173
		dependsOn(check)
174
	}
175
} else {
176
	println "cmakeBuildDir is not set. Skipping cmake tasks."
177
}
178

179
dependencies {
180
	testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
181
	testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
182
	testImplementation 'com.google.protobuf:protobuf-java:3.21.7'
183
}
184

185
processTestResources {
186
	duplicatesStrategy(DuplicatesStrategy.INCLUDE) // allows duplicates in the test resources
187
}
188

189
test {
190
	java {
191
		dependsOn spotlessJava
192
	}
193
	if (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.
196
		forkEvery 1
197
	}
198
	useJUnitPlatform()
199
	if (cmakeBuildDir != null) {
200
		workingDir cmakeBuildDir
201
	}
202
	systemProperties System.getProperties().subMap(['USE_CUDA', 'USE_ROCM', 'USE_TENSORRT', 'USE_DNNL', 'USE_OPENVINO', 'USE_COREML', 'USE_DML', 'JAVA_FULL_TEST', 'ENABLE_TRAINING_APIS'])
203
	testLogging {
204
		events "passed", "skipped", "failed"
205
		showStandardStreams = true
206
		showStackTraces = true
207
		exceptionFormat = "full"
208
	}
209
}
210

211
jacocoTestReport {
212
	reports {
213
		xml.required = true
214
		csv.required = true
215
		html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
216
	}
217
}
218

219
publishing {
220
	publications {
221
		maven(MavenPublication) {
222
			groupId = project.group
223
			if(publishToAdo) {
224
				artifactId = 'onnxruntime_gpu'
225
				artifact (adoArtifact)
226
			} else {
227
				artifactId = mavenArtifactId
228
				from components.java
229
			}
230
			version = project.version
231
			pom {
232
				name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
233
				description = enableTrainingApis ? trainingDescription : defaultDescription
234
				url = 'https://microsoft.github.io/onnxruntime/'
235
				licenses {
236
					license {
237
						name = 'MIT License'
238
						url = 'https://opensource.org/licenses/MIT'
239
					}
240
				}
241
				organization {
242
					name = 'Microsoft'
243
					url = 'https://www.microsoft.com'
244
				}
245
				scm {
246
					connection = 'scm:git:git://github.com:microsoft/onnxruntime.git'
247
					developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime.git'
248
					url = 'https://github.com/microsoft/onnxruntime'
249
				}
250
				developers {
251
					developer {
252
						id = 'onnxruntime'
253
						name = 'ONNX Runtime'
254
						email = 'onnxruntime@microsoft.com'
255
					}
256
				}
257
			}
258
		}
259
	}
260
	repositories {
261
		if (publishToAdo) {
262
			maven {
263
				url "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/${System.getenv('ADOFeedName')}/maven/v1"
264
				name System.getenv('ADOFeedName')
265
				authentication {
266
					basic(BasicAuthentication)
267
				}
268
				credentials {
269
					username  'aiinfra'
270
					password "${project.findProperty('adoAccessToken')}"
271
				}
272
			}
273
		} else {
274
			maven {
275
				url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
276
				credentials {
277
					username mavenUser
278
					password mavenPwd
279
				}
280
			}
281
		}
282
	}
283
}
284
// Generates a task signMavenPublication that will
285
// build all artifacts.
286
signing {
287
	// Queries env vars:
288
	// ORG_GRADLE_PROJECT_signingKey
289
	// ORG_GRADLE_PROJECT_signingPassword but can be changed to properties
290
		def signingKey = findProperty("signingKey")
291
		def signingPassword = findProperty("signingPassword")
292
		// Skip signing if no key is provided
293
		if (signingKey != null && signingPassword != null) {
294
			useInMemoryPgpKeys(signingKey, signingPassword)
295
			sign publishing.publications.maven
296
			sign publishing.publications.mavenAdo
297
		}
298
}
299

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.