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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. plugins {
  17. id 'java'
  18. id 'maven-publish'
  19. id 'java-library'
  20. }
  21. final String JAVA9_SRC = 'src/main/java9'
  22. final String JAVA9_OUT = "${buildDir}/classes/java9/main/"
  23. final String TEST9_SRC = 'src/test/java9'
  24. final String TEST9_OUT = "${buildDir}/classes/java9/test/"
  25. final String VERSIONS9 = 'META-INF/versions/9'
  26. configurations {
  27. all {
  28. exclude group: 'xalan', module: 'xalan'
  29. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  30. exclude group: 'xml-apis', module: 'xml-apis'
  31. }
  32. }
  33. broken
  34. tests
  35. javadocs
  36. }
  37. sourceSets {
  38. main {
  39. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  40. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  41. }
  42. }
  43. test {
  44. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  45. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  46. }
  47. }
  48. }
  49. dependencies {
  50. api project(':poi')
  51. api project(':poi-ooxml-full')
  52. api project(path: ':poi', configuration: 'archives')
  53. api project(path: ':poi-ooxml-full', configuration: 'archives')
  54. implementation 'org.apache.commons:commons-collections4:4.4'
  55. api "org.apache.commons:commons-compress:${commonsCompressVersion}"
  56. api 'org.apache.santuario:xmlsec:2.2.1'
  57. api "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  58. api 'com.github.virtuald:curvesapi:1.06'
  59. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  60. implementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}"
  61. implementation "org.apache.xmlgraphics:batik-bridge:${batikVersion}"
  62. implementation "org.apache.xmlgraphics:batik-codec:${batikVersion}"
  63. implementation "org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}"
  64. api 'de.rototor.pdfbox:graphics2d:0.30'
  65. testImplementation project(':poi-scratchpad')
  66. testImplementation project(path:':poi', configuration:'tests')
  67. testImplementation project(path:':poi-ooxml-lite-agent', configuration: 'archives')
  68. testImplementation project(path:':poi-scratchpad', configuration:'tests')
  69. testImplementation 'org.xmlunit:xmlunit-core:2.8.0'
  70. testImplementation 'org.reflections:reflections:0.9.12'
  71. testImplementation 'org.openjdk.jmh:jmh-core:1.26'
  72. testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.26'
  73. testImplementation 'com.google.guava:guava:30.0-jre'
  74. broken "org.apache.xmlgraphics:batik-script:${batikVersion}"
  75. javadocs project(':poi')
  76. javadocs project(':poi-scratchpad')
  77. }
  78. final String MODULE_NAME = 'org.apache.poi.ooxml'
  79. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  80. final Pattern MODULE_REGEX = ~'\\.jar$'
  81. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  82. 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")
  83. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  84. final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
  85. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  86. java {
  87. sourceCompatibility = JavaVersion.VERSION_1_8
  88. targetCompatibility = JavaVersion.VERSION_1_8
  89. withJavadocJar()
  90. withSourcesJar()
  91. }
  92. compileJava {
  93. dependsOn 'fixBatik'
  94. }
  95. task compileJava9(type: JavaCompile) {
  96. dependsOn 'compileJava', ':poi:jar'
  97. sourceCompatibility = 9
  98. targetCompatibility = 9
  99. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  100. source = file(JAVA9_SRC)
  101. classpath = files()
  102. options.compilerArgs = [
  103. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  104. '--module-path', files(MAIN_MODULE_PATH).asPath
  105. ]
  106. }
  107. task cacheJava9(type: Copy) {
  108. dependsOn 'compileJava9'
  109. from(file(JAVA9_OUT + VERSIONS9))
  110. into(JAVA9_SRC)
  111. }
  112. task compileTest9(type: JavaCompile) {
  113. dependsOn 'compileTestJava', ':poi:testJar'
  114. sourceCompatibility = 9
  115. targetCompatibility = 9
  116. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  117. source = file(TEST9_SRC)
  118. options.compilerArgs = [
  119. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  120. '--module-path', files(TEST_MODULE_PATH).asPath
  121. ]
  122. classpath = files()
  123. }
  124. task cacheTest9(type: Copy) {
  125. dependsOn 'compileTest9'
  126. from(file(TEST9_OUT + VERSIONS9))
  127. into(TEST9_SRC)
  128. }
  129. jar {
  130. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  131. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  132. into('META-INF/versions/9') {
  133. from JAVA9_SRC include '*.class'
  134. }
  135. }
  136. manifest {
  137. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  138. }
  139. }
  140. // Create a separate jar for test-code to depend on it in other projects
  141. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  142. task testJar(type: Jar, dependsOn: testClasses) {
  143. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  144. classifier 'tests'
  145. // ignore second module-info.class from main
  146. duplicatesStrategy = 'exclude'
  147. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  148. into('META-INF/versions/9') {
  149. from TEST9_SRC include '*.class'
  150. }
  151. }
  152. from sourceSets.test.output + sourceSets.main.output
  153. manifest {
  154. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  155. }
  156. }
  157. sourcesJar {
  158. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  159. exclude 'META-INF/services/**'
  160. }
  161. // based on https://github.com/moditect/moditect-gradle-plugin/issues/12
  162. task fixBatik(type: Zip) {
  163. ant.mkdir(dir: "${buildDir}/brokenJars")
  164. archiveFileName = "batik-script-${batikVersion}.jar"
  165. destinationDirectory = file("${buildDir}/brokenJars")
  166. from zipTree(configurations.broken.files.find{ f -> f.name.startsWith("batik-script") })
  167. filesMatching("**/org.apache.batik.script.InterpreterFactory") {
  168. it.filter{ it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
  169. }
  170. }
  171. javadoc {
  172. failOnError = true
  173. doFirst {
  174. options {
  175. if (JavaVersion.current().isJava9Compatible()) {
  176. addBooleanOption('html5', true)
  177. }
  178. links 'https://poi.apache.org/apidocs/dev/'
  179. links 'https://docs.oracle.com/javase/8/docs/api/'
  180. use = true
  181. splitIndex = true
  182. source = "1.8"
  183. classpath += configurations.javadocs.files
  184. }
  185. }
  186. }
  187. artifacts {
  188. tests testJar
  189. }
  190. test {
  191. // for some reason catching the OOM does not work when run from Gradle
  192. exclude '**/MemoryUsage.class'
  193. dependsOn { testJar }
  194. useJUnitPlatform()
  195. doFirst {
  196. jvmArgs = [
  197. '-Djava.io.tmpdir=build',
  198. '-DPOI.testdata.path=../test-data',
  199. '-Djava.awt.headless=true',
  200. '-Djava.locale.providers=JRE,CLDR',
  201. '-Duser.language=en',
  202. '-Duser.country=US',
  203. '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
  204. "-Dversion.id=${project.version}",
  205. '-ea',
  206. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
  207. '-Djunit.jupiter.execution.parallel.enabled=true',
  208. '-Djunit.jupiter.execution.parallel.config.strategy=fixed',
  209. '-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
  210. // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
  211. ]
  212. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  213. jvmArgs += [
  214. '-Dsun.reflect.debugModuleAccessChecks=true',
  215. '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
  216. '--illegal-access=warn',
  217. '--add-modules', MODULE_NAME,
  218. // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
  219. // opposed to the recommendation there, it doesn't work to add ... to the dependencies
  220. // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
  221. // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
  222. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
  223. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
  224. '--module-path', '../build/dist/maven/poi-ooxml-tests:' + files(TEST_MODULE_PATH).asPath,
  225. ]
  226. }
  227. }
  228. }
  229. publishing {
  230. publications {
  231. POI(MavenPublication) {
  232. artifactId project.archivesBaseName
  233. from components.java
  234. pom {
  235. name = 'Apache POI - API based on OPC and OOXML schemas'
  236. description = 'Apache POI - Java API To Access Microsoft Format Files'
  237. }
  238. }
  239. }
  240. }
  241. generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"