microsoft/onnxruntime-extensions

Public

mirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.14.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

java/build.gradle

246lines · modeblame

08659eaeWenbing Li3 years ago1plugins {
66be6bb6Wenbing Li2 years ago2id 'java-library'
3id 'maven-publish'
4id 'signing'
5id 'jacoco'
2aeca727Edward Chen2 years ago6id 'com.diffplug.spotless' version '6.22.0'
08659eaeWenbing Li3 years ago7}
8
9allprojects {
66be6bb6Wenbing Li2 years ago10repositories {
11mavenCentral()
12}
08659eaeWenbing Li3 years ago13}
14
15project.group = "com.microsoft.onnxruntime"
63fe165eEdward Chen3 years ago16project.version = rootProject.file('../version.txt').text.trim()
08659eaeWenbing Li3 years ago17
18// cmake runs will inform us of the build directory of the current run
19def cmakeBuildDir = System.properties['cmakeBuildDir']
20def cmakeJavaDir = "${cmakeBuildDir}/java"
21def cmakeNativeLibDir = "${cmakeJavaDir}/native-lib"
22def cmakeNativeJniDir = "${cmakeJavaDir}/native-jni"
23def cmakeNativeTestDir = "${cmakeJavaDir}/native-test"
24def cmakeBuildOutputDir = "${cmakeJavaDir}/build"
25
26def mavenUser = System.properties['mavenUser']
27def mavenPwd = System.properties['mavenPwd']
28
29def mavenArtifactId = project.name
30
31java {
66be6bb6Wenbing Li2 years ago32sourceCompatibility = JavaVersion.VERSION_1_8
33targetCompatibility = JavaVersion.VERSION_1_8
08659eaeWenbing Li3 years ago34}
35
36// This jar tasks serves as a CMAKE signalling
37// mechanism. The jar will be overwritten by allJar task
38jar {
39}
40
41// Add explicit sources jar with pom file.
42task sourcesJar(type: Jar, dependsOn: classes) {
66be6bb6Wenbing Li2 years ago43archiveClassifier = "sources"
44from sourceSets.main.allSource
45into("META-INF/maven/$project.group/$mavenArtifactId") {
46from { generatePomFileForMavenPublication }
47rename ".*", "pom.xml"
48}
08659eaeWenbing Li3 years ago49}
50
51// Add explicit javadoc jar with pom file
52task javadocJar(type: Jar, dependsOn: javadoc) {
66be6bb6Wenbing Li2 years ago53archiveClassifier = "javadoc"
54from javadoc.destinationDir
55into("META-INF/maven/$project.group/$mavenArtifactId") {
56from { generatePomFileForMavenPublication }
57rename ".*", "pom.xml"
58}
08659eaeWenbing Li3 years ago59}
60
61spotless {
66be6bb6Wenbing Li2 years ago62java {
63removeUnusedImports()
64googleJavaFormat()
65}
66format 'gradle', {
67target '**/*.gradle'
68trimTrailingWhitespace()
69indentWithTabs()
70}
08659eaeWenbing Li3 years ago71}
72
73compileJava {
66be6bb6Wenbing Li2 years ago74dependsOn spotlessJava
75options.compilerArgs += ["-h", "${project.buildDir}/headers/"]
76if (!JavaVersion.current().isJava8()) {
77// Ensures only methods present in Java 8 are used
78options.compilerArgs.addAll(['--release', '8'])
79// Gradle versions before 6.6 require that these flags are unset when using "-release"
80java.sourceCompatibility = null
81java.targetCompatibility = null
82}
08659eaeWenbing Li3 years ago83}
84
85compileTestJava {
66be6bb6Wenbing Li2 years ago86if (!JavaVersion.current().isJava8()) {
87// Ensures only methods present in Java 8 are used
88options.compilerArgs.addAll(['--release', '8'])
89// Gradle versions before 6.6 require that these flags are unset when using "-release"
90java.sourceCompatibility = null
91java.targetCompatibility = null
92}
08659eaeWenbing Li3 years ago93}
94
95sourceSets.test {
66be6bb6Wenbing Li2 years ago96// add test resource files
97resources.srcDirs += [
98"${rootProject.projectDir}/../java/testdata"
99]
100if (cmakeBuildDir != null) {
101// add compiled native libs
102resources.srcDirs += [
103cmakeNativeLibDir,
104cmakeNativeJniDir,
105cmakeNativeTestDir
106]
107}
08659eaeWenbing Li3 years ago108}
109
110if (cmakeBuildDir != null) {
66be6bb6Wenbing Li2 years ago111// generate tasks to be called from cmake
112
113// Overwrite jar location
114task allJar(type: Jar) {
115manifest {
fcf28fe8Adam Pocock2 years ago116attributes('Automatic-Module-Name': "com.microsoft.onnxruntime.extensions",
66be6bb6Wenbing Li2 years ago117'Implementation-Title': 'onnxruntime-extensions',
118'Implementation-Version': project.version)
119}
120into("META-INF/maven/$project.group/$mavenArtifactId") {
121from { generatePomFileForMavenPublication }
122rename ".*", "pom.xml"
123}
124from sourceSets.main.output
125from cmakeNativeJniDir
126from cmakeNativeLibDir
127}
128
129task cmakeBuild(type: Copy) {
130from project.buildDir
131include 'libs/**'
132include 'docs/**'
133into cmakeBuildOutputDir
134}
135cmakeBuild.dependsOn allJar
136cmakeBuild.dependsOn sourcesJar
137cmakeBuild.dependsOn javadocJar
138cmakeBuild.dependsOn javadoc
139
140task cmakeCheck(type: Copy) {
141from project.buildDir
142include 'reports/**'
143into cmakeBuildOutputDir
144}
145cmakeCheck.dependsOn check
08659eaeWenbing Li3 years ago146}
147
148dependencies {
66be6bb6Wenbing Li2 years ago149testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
150testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
a1285d8fScott McKay2 years ago151testImplementation 'com.google.protobuf:protobuf-java:3.21.7'
08659eaeWenbing Li3 years ago152}
153
154processTestResources {
66be6bb6Wenbing Li2 years ago155duplicatesStrategy(DuplicatesStrategy.INCLUDE) // allows duplicates in the test resources
08659eaeWenbing Li3 years ago156}
157
158test {
66be6bb6Wenbing Li2 years ago159java {
160dependsOn spotlessJava
161}
162if (System.getProperty("JAVA_FULL_TEST") != null) {
163// Forces each test class to be run in a separate JVM,
164// which is necessary for testing the environment thread pool which is ignored if full test is not set.
165forkEvery 1
166}
167useJUnitPlatform()
168if (cmakeBuildDir != null) {
169workingDir cmakeBuildDir
170}
171systemProperties System.getProperties().subMap(['JAVA_FULL_TEST'])
172testLogging {
173events "passed", "skipped", "failed"
174showStandardStreams = true
175showStackTraces = true
176exceptionFormat = "full"
177}
08659eaeWenbing Li3 years ago178}
179
180jacocoTestReport {
66be6bb6Wenbing Li2 years ago181reports {
182xml.required = true
183csv.required = true
184html.destination file("${buildDir}/jacocoHtml")
185}
08659eaeWenbing Li3 years ago186}
187
188publishing {
66be6bb6Wenbing Li2 years ago189publications {
190maven(MavenPublication) {
191groupId = project.group
192artifactId = mavenArtifactId
193version = project.version
194
195from components.java
196pom {
197name = 'onnxruntime-extensions'
198description = 'ONNXRuntime-Extensions is a library for pre- and post-processing.'
199url = 'https://microsoft.github.io/onnxruntime/'
200licenses {
201license {
202name = 'MIT License'
203url = 'https://opensource.org/licenses/MIT'
204}
205}
206organization {
207name = 'Microsoft'
208url = 'http://www.microsoft.com'
209}
210scm {
211connection = 'scm:git:git://github.com:microsoft/onnxruntime-extensions.git'
212developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime-extensions.git'
213url = 'http://github.com/microsoft/onnxruntime-extensions'
214}
215developers {
216developer {
217id = 'onnxruntime'
218name = 'ONNX Runtime'
219email = 'onnxruntime@microsoft.com'
220}
221}
222}
223}
224}
225repositories {
226maven {
227url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
228credentials {
229username mavenUser
230password mavenPwd
231}
232}
233}
08659eaeWenbing Li3 years ago234}
235
236// Generates a task signMavenPublication that will
237// build all artifacts.
238signing {
66be6bb6Wenbing Li2 years ago239// Queries env vars:
240// ORG_GRADLE_PROJECT_signingKey
241// ORG_GRADLE_PROJECT_signingPassword but can be changed to properties
242def signingKey = findProperty("signingKey")
243def signingPassword = findProperty("signingPassword")
244useInMemoryPgpKeys(signingKey, signingPassword)
245sign publishing.publications.maven
08659eaeWenbing Li3 years ago246}