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

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