You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. import java.util.regex.Pattern
  16. configurations {
  17. runtimeClasspath {
  18. exclude group: 'xalan', module: 'xalan'
  19. if (jdkVersion > 8) {
  20. exclude group: 'xml-apis', module: 'xml-apis'
  21. }
  22. }
  23. compileClasspath {
  24. exclude group: 'xalan', module: 'xalan'
  25. if (jdkVersion > 8) {
  26. exclude group: 'xml-apis', module: 'xml-apis'
  27. }
  28. }
  29. broken
  30. tests
  31. javadocs
  32. }
  33. sourceSets {
  34. main {
  35. if (jdkVersion > 8) {
  36. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  37. }
  38. }
  39. test {
  40. if (jdkVersion > 8) {
  41. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  42. }
  43. }
  44. }
  45. java {
  46. registerFeature('signing') {
  47. usingSourceSet(sourceSets.main)
  48. }
  49. registerFeature('render') {
  50. usingSourceSet(sourceSets.main)
  51. }
  52. registerFeature('rendersign') {
  53. usingSourceSet(sourceSets.main)
  54. }
  55. }
  56. dependencies {
  57. api project(':poi')
  58. api project(':poi-ooxml-full')
  59. api project(path: ':poi-ooxml-full', configuration: 'archives')
  60. api "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  61. api "org.apache.commons:commons-compress:${commonsCompressVersion}"
  62. api "commons-io:commons-io:${commonsIoVersion}"
  63. api 'com.github.virtuald:curvesapi:1.07'
  64. api "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  65. api 'org.apache.commons:commons-collections4:4.4'
  66. signingImplementation 'org.apache.santuario:xmlsec:3.0.1'
  67. signingImplementation "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  68. signingImplementation "org.bouncycastle:bcutil-jdk15on:${bouncyCastleVersion}"
  69. rendersignImplementation 'org.apache.santuario:xmlsec:3.0.1'
  70. rendersignImplementation "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  71. rendersignImplementation "org.bouncycastle:bcutil-jdk15on:${bouncyCastleVersion}"
  72. renderImplementation "org.apache.pdfbox:pdfbox:${pdfboxVersion}"
  73. renderImplementation "de.rototor.pdfbox:graphics2d:${graphics2dVersion}"
  74. renderImplementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}"
  75. renderImplementation("org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}") {
  76. exclude group: 'xalan', module: 'xalan'
  77. if (jdkVersion > 8) {
  78. exclude group: 'xml-apis', module: 'xml-apis'
  79. }
  80. }
  81. renderImplementation("org.apache.xmlgraphics:batik-codec:${batikVersion}") {
  82. exclude group: 'xalan', module: 'xalan'
  83. if (jdkVersion > 8) {
  84. exclude group: 'xml-apis', module: 'xml-apis'
  85. }
  86. }
  87. renderImplementation("org.apache.xmlgraphics:batik-bridge:${batikVersion}") {
  88. exclude group: 'xalan', module: 'xalan'
  89. if (jdkVersion > 8) {
  90. exclude group: 'xml-apis', module: 'xml-apis'
  91. }
  92. }
  93. rendersignImplementation "org.apache.pdfbox:pdfbox:${pdfboxVersion}"
  94. rendersignImplementation "de.rototor.pdfbox:graphics2d:${graphics2dVersion}"
  95. rendersignImplementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}"
  96. rendersignImplementation("org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}") {
  97. exclude group: 'xalan', module: 'xalan'
  98. if (jdkVersion > 8) {
  99. exclude group: 'xml-apis', module: 'xml-apis'
  100. }
  101. }
  102. rendersignImplementation("org.apache.xmlgraphics:batik-codec:${batikVersion}") {
  103. exclude group: 'xalan', module: 'xalan'
  104. if (jdkVersion > 8) {
  105. exclude group: 'xml-apis', module: 'xml-apis'
  106. }
  107. }
  108. rendersignImplementation("org.apache.xmlgraphics:batik-bridge:${batikVersion}") {
  109. exclude group: 'xalan', module: 'xalan'
  110. if (jdkVersion > 8) {
  111. exclude group: 'xml-apis', module: 'xml-apis'
  112. }
  113. }
  114. if (!NO_SCRATCHPAD) {
  115. testImplementation project(':poi-scratchpad')
  116. testImplementation project(path:':poi-scratchpad', configuration:'tests')
  117. }
  118. testImplementation project(path:':poi', configuration:'tests')
  119. testImplementation project(path:':poi-ooxml-lite-agent', configuration: 'archives')
  120. testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
  121. testImplementation 'org.xmlunit:xmlunit-core:2.9.0'
  122. testImplementation 'org.reflections:reflections:0.10.2'
  123. testImplementation 'org.openjdk.jmh:jmh-core:1.35'
  124. testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
  125. testImplementation 'com.google.guava:guava:31.1-jre'
  126. testImplementation 'org.tukaani:xz:1.9'
  127. testImplementation 'com.github.rzymek:opczip:1.2.0'
  128. // prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.x dependency
  129. // see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
  130. testImplementation "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}"
  131. testImplementation 'org.slf4j:slf4j-simple:2.0.3'
  132. if (SAXON_TEST) {
  133. testRuntimeOnly "net.sf.saxon:Saxon-HE:${saxonVersion}"
  134. }
  135. broken("org.apache.xmlgraphics:batik-script:${batikVersion}"){
  136. exclude group: 'xalan', module: 'xalan'
  137. if (jdkVersion > 8) {
  138. exclude group: 'xml-apis', module: 'xml-apis'
  139. }
  140. }
  141. javadocs project(':poi')
  142. javadocs project(':poi-scratchpad')
  143. }
  144. final String MODULE_NAME = 'org.apache.poi.ooxml'
  145. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  146. final Pattern MODULE_REGEX = ~'\\.jar$'
  147. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  148. final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique() + files("build/brokenJars")
  149. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  150. final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
  151. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  152. compileJava {
  153. dependsOn 'fixBatik'
  154. }
  155. task compileJava9(type: JavaCompile) {
  156. dependsOn 'compileJava', ':poi:jar'
  157. javaCompiler = javaToolchains.compilerFor {
  158. languageVersion = JavaLanguageVersion.of(jdkVersion)
  159. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  160. }
  161. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  162. source = file(JAVA9_SRC)
  163. classpath = files()
  164. options.compilerArgs = [
  165. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  166. '--module-path', files(MAIN_MODULE_PATH).asPath
  167. ]
  168. onlyIf {
  169. jdkVersion > 8
  170. }
  171. }
  172. task cacheJava9(type: Copy) {
  173. dependsOn 'compileJava9'
  174. from(file(JAVA9_OUT + VERSIONS9))
  175. into(JAVA9_SRC)
  176. }
  177. task compileTest9(type: JavaCompile) {
  178. dependsOn 'compileTestJava', ':poi:testJar'
  179. javaCompiler = javaToolchains.compilerFor {
  180. languageVersion = JavaLanguageVersion.of(jdkVersion >= 17 ? 17 : 11)
  181. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  182. }
  183. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  184. source = file(TEST9_SRC)
  185. options.compilerArgs = [
  186. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  187. '--module-path', files(TEST_MODULE_PATH).asPath
  188. ]
  189. classpath = files()
  190. onlyIf {
  191. jdkVersion > 8
  192. }
  193. }
  194. task cacheTest9(type: Copy) {
  195. dependsOn 'compileTest9'
  196. from(file(TEST9_OUT + VERSIONS9))
  197. into(TEST9_SRC)
  198. }
  199. jar {
  200. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  201. if (jdkVersion == 8) {
  202. into('META-INF/versions/9') {
  203. from JAVA9_SRC include '*.class'
  204. }
  205. }
  206. manifest {
  207. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  208. }
  209. }
  210. // Create a separate jar for test-code to depend on it in other projects
  211. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  212. task testJar(type: Jar, dependsOn: testClasses) {
  213. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  214. classifier 'tests'
  215. // ignore second module-info.class from main
  216. duplicatesStrategy = 'exclude'
  217. if (jdkVersion == 8) {
  218. into('META-INF/versions/9') {
  219. from TEST9_SRC include '*.class'
  220. }
  221. }
  222. from sourceSets.test.output + sourceSets.main.output
  223. manifest {
  224. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  225. }
  226. }
  227. // based on https://github.com/moditect/moditect-gradle-plugin/issues/12
  228. task fixBatik(type: Zip) {
  229. ant.mkdir(dir: "${buildDir}/brokenJars")
  230. archiveFileName = "batik-script-${batikVersion}.jar"
  231. destinationDirectory = file("${buildDir}/brokenJars")
  232. from zipTree(configurations.broken.files.find{ f -> f.name.startsWith("batik-script") })
  233. filesMatching("**/org.apache.batik.script.InterpreterFactory") {
  234. it.filter{ it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
  235. }
  236. }
  237. javadoc {
  238. failOnError = true
  239. doFirst {
  240. options {
  241. if (JavaVersion.current().isJava9Compatible()) {
  242. addBooleanOption('html5', true)
  243. }
  244. links 'https://poi.apache.org/apidocs/dev/'
  245. links 'https://docs.oracle.com/javase/8/docs/api/'
  246. use = true
  247. splitIndex = true
  248. source = "1.8"
  249. classpath += configurations.javadocs.files
  250. }
  251. }
  252. }
  253. javadocJar {
  254. metaInf {
  255. from("$projectDir/../legal/LICENSE")
  256. from("$projectDir/../legal/NOTICE")
  257. }
  258. }
  259. sourcesJar {
  260. metaInf {
  261. from("$projectDir/../legal/LICENSE")
  262. from("$projectDir/../legal/NOTICE")
  263. }
  264. }
  265. artifacts {
  266. tests testJar
  267. }
  268. test {
  269. // for some reason catching the OOM does not work when run from Gradle
  270. exclude '**/MemoryUsage.class'
  271. dependsOn { testJar }
  272. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  273. if (NO_SCRATCHPAD) {
  274. useJUnitPlatform {
  275. excludeTags 'scratchpad.ignore'
  276. }
  277. }
  278. doFirst {
  279. jvmArgs += [
  280. "-Xverify:all",
  281. "-XX:ErrorFile=../build/hs_err_pid%p.log",
  282. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}"
  283. ]
  284. if (jdkVersion > 8) {
  285. jvmArgs += [
  286. '--add-modules', MODULE_NAME,
  287. '--module-path', '../build/dist/maven/poi-ooxml-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  288. ]
  289. }
  290. }
  291. }
  292. publishing {
  293. publications {
  294. POI(MavenPublication) {
  295. pom {
  296. name = 'Apache POI - API based on OPC and OOXML schemas'
  297. description = 'Apache POI - Java API To Access Microsoft Format Files'
  298. }
  299. suppressPomMetadataWarningsFor('renderApiElements')
  300. suppressPomMetadataWarningsFor('renderRuntimeElements')
  301. suppressPomMetadataWarningsFor('signingApiElements')
  302. suppressPomMetadataWarningsFor('signingRuntimeElements')
  303. suppressPomMetadataWarningsFor('rendersignApiElements')
  304. suppressPomMetadataWarningsFor('rendersignRuntimeElements')
  305. }
  306. }
  307. }