microsoft/onnxruntime-extensions

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e3d9198de801fe80ec3896063e016f9db8cf2be2

Branches

Tags

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

Clone

HTTPS

Download ZIP

java/build.gradle

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