microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0169129b19715e12031e1f6378121bd671ea7ce3

Branches

Tags

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

Clone

HTTPS

Download ZIP

java/build.gradle

249lines · modecode

1plugins {
2 id 'java-library'
3 id 'maven-publish'
4 id 'signing'
5 id 'jacoco'
6 id 'com.diffplug.spotless' version '5.17.0'
7}
8
9allprojects {
10 repositories {
11 mavenCentral()
12 }
13}
14
15project.group = "com.microsoft.onnxruntime"
16version = rootProject.file('../version.txt').text.trim()
17
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 {
32 sourceCompatibility = JavaVersion.VERSION_1_8
33 targetCompatibility = JavaVersion.VERSION_1_8
34}
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) {
43 classifier = "sources"
44 from sourceSets.main.allSource
45 into("META-INF/maven/$project.group/$mavenArtifactId") {
46 from { generatePomFileForMavenPublication }
47 rename ".*", "pom.xml"
48 }
49}
50
51// Add explicit javadoc jar with pom file
52task javadocJar(type: Jar, dependsOn: javadoc) {
53 classifier = "javadoc"
54 from javadoc.destinationDir
55 into("META-INF/maven/$project.group/$mavenArtifactId") {
56 from { generatePomFileForMavenPublication }
57 rename ".*", "pom.xml"
58 }
59}
60
61wrapper {
62 gradleVersion = '6.1.1'
63}
64
65spotless {
66 java {
67 removeUnusedImports()
68 googleJavaFormat()
69 }
70 format 'gradle', {
71 target '**/*.gradle'
72 trimTrailingWhitespace()
73 indentWithTabs()
74 }
75}
76
77compileJava {
78 dependsOn spotlessJava
79 options.compilerArgs += ["-h", "${project.buildDir}/headers/"]
80 if (!JavaVersion.current().isJava8()) {
81 // Ensures only methods present in Java 8 are used
82 options.compilerArgs.addAll(['--release', '8'])
83 // Gradle versions before 6.6 require that these flags are unset when using "-release"
84 java.sourceCompatibility = null
85 java.targetCompatibility = null
86 }
87}
88
89compileTestJava {
90 if (!JavaVersion.current().isJava8()) {
91 // Ensures only methods present in Java 8 are used
92 options.compilerArgs.addAll(['--release', '8'])
93 // Gradle versions before 6.6 require that these flags are unset when using "-release"
94 java.sourceCompatibility = null
95 java.targetCompatibility = null
96 }
97}
98
99sourceSets.test {
100 // add test resource files
101 resources.srcDirs += [
102 "${rootProject.projectDir}/../java/testdata"
103 ]
104 if (cmakeBuildDir != null) {
105 // add compiled native libs
106 resources.srcDirs += [
107 cmakeNativeLibDir,
108 cmakeNativeJniDir,
109 cmakeNativeTestDir
110 ]
111 }
112}
113
114if (cmakeBuildDir != null) {
115 // generate tasks to be called from cmake
116
117 // Overwrite jar location
118 task allJar(type: Jar) {
119 manifest {
120 attributes('Automatic-Module-Name': project.group,
121 'Implementation-Title': 'onnxruntime-extensions',
122 'Implementation-Version': project.version)
123 }
124 into("META-INF/maven/$project.group/$mavenArtifactId") {
125 from { generatePomFileForMavenPublication }
126 rename ".*", "pom.xml"
127 }
128 from sourceSets.main.output
129 from cmakeNativeJniDir
130 from cmakeNativeLibDir
131 }
132
133 task cmakeBuild(type: Copy) {
134 from project.buildDir
135 include 'libs/**'
136 include 'docs/**'
137 into cmakeBuildOutputDir
138 }
139 cmakeBuild.dependsOn allJar
140 cmakeBuild.dependsOn sourcesJar
141 cmakeBuild.dependsOn javadocJar
142 cmakeBuild.dependsOn javadoc
143
144 task cmakeCheck(type: Copy) {
145 from project.buildDir
146 include 'reports/**'
147 into cmakeBuildOutputDir
148 }
149 cmakeCheck.dependsOn check
150}
151
152dependencies {
153 testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
154 testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
155 testImplementation 'com.google.protobuf:protobuf-java:3.20.1'
156}
157
158processTestResources {
159 duplicatesStrategy(DuplicatesStrategy.INCLUDE) // allows duplicates in the test resources
160}
161
162test {
163 java {
164 dependsOn spotlessJava
165 }
166 if (System.getProperty("JAVA_FULL_TEST") != null) {
167 // Forces each test class to be run in a separate JVM,
168 // which is necessary for testing the environment thread pool which is ignored if full test is not set.
169 forkEvery 1
170 }
171 useJUnitPlatform()
172 if (cmakeBuildDir != null) {
173 workingDir cmakeBuildDir
174 }
175 systemProperties System.getProperties().subMap(['JAVA_FULL_TEST'])
176 testLogging {
177 events "passed", "skipped", "failed"
178 showStandardStreams = true
179 showStackTraces = true
180 exceptionFormat = "full"
181 }
182}
183
184jacocoTestReport {
185 reports {
186 xml.enabled true
187 csv.enabled true
188 html.destination file("${buildDir}/jacocoHtml")
189 }
190}
191
192publishing {
193 publications {
194 maven(MavenPublication) {
195 groupId = project.group
196 artifactId = mavenArtifactId
197
198 from components.java
199 pom {
200 name = 'onnxruntime-extensions'
201 description = 'ONNXRuntime-Extensions is a library for Android for pre- and post-processing on inference.'
202 url = 'https://microsoft.github.io/onnxruntime/'
203 licenses {
204 license {
205 name = 'MIT License'
206 url = 'https://opensource.org/licenses/MIT'
207 }
208 }
209 organization {
210 name = 'Microsoft'
211 url = 'http://www.microsoft.com'
212 }
213 scm {
214 connection = 'scm:git:git://github.com:microsoft/onnxruntime-extensions.git'
215 developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime-extensions.git'
216 url = 'http://github.com/microsoft/onnxruntime-extensions'
217 }
218 developers {
219 developer {
220 id = 'onnxruntime'
221 name = 'ONNX Runtime'
222 email = 'onnxruntime@microsoft.com'
223 }
224 }
225 }
226 }
227 }
228 repositories {
229 maven {
230 url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
231 credentials {
232 username mavenUser
233 password mavenPwd
234 }
235 }
236 }
237}
238
239// Generates a task signMavenPublication that will
240// build all artifacts.
241signing {
242 // Queries env vars:
243 // ORG_GRADLE_PROJECT_signingKey
244 // ORG_GRADLE_PROJECT_signingPassword but can be changed to properties
245 def signingKey = findProperty("signingKey")
246 def signingPassword = findProperty("signingPassword")
247 useInMemoryPgpKeys(signingKey, signingPassword)
248 sign publishing.publications.maven
249}
250