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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. all {
  18. exclude group: 'xalan', module: 'xalan'
  19. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  20. exclude group: 'xml-apis', module: 'xml-apis'
  21. }
  22. }
  23. broken
  24. tests
  25. javadocs
  26. }
  27. sourceSets {
  28. main {
  29. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  30. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  31. }
  32. }
  33. test {
  34. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  35. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  36. }
  37. }
  38. }
  39. dependencies {
  40. api project(':poi')
  41. api project(':poi-ooxml-full')
  42. api project(path: ':poi', configuration: 'archives')
  43. api project(path: ':poi-ooxml-full', configuration: 'archives')
  44. implementation 'org.apache.commons:commons-collections4:4.4'
  45. api "org.apache.commons:commons-compress:${commonsCompressVersion}"
  46. api "commons-io:commons-io:${commonsIoVersion}"
  47. api 'org.apache.santuario:xmlsec:2.2.2'
  48. api "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  49. api "org.bouncycastle:bcutil-jdk15on:${bouncyCastleVersion}"
  50. api 'com.github.virtuald:curvesapi:1.06'
  51. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  52. implementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}"
  53. implementation "org.apache.xmlgraphics:batik-bridge:${batikVersion}"
  54. implementation "org.apache.xmlgraphics:batik-codec:${batikVersion}"
  55. implementation "org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}"
  56. api 'de.rototor.pdfbox:graphics2d:0.32'
  57. testImplementation project(':poi-scratchpad')
  58. testImplementation project(path:':poi', configuration:'tests')
  59. testImplementation project(path:':poi-ooxml-lite-agent', configuration: 'archives')
  60. testImplementation project(path:':poi-scratchpad', configuration:'tests')
  61. testImplementation 'org.xmlunit:xmlunit-core:2.8.0'
  62. testImplementation 'org.reflections:reflections:0.9.12'
  63. testImplementation 'org.openjdk.jmh:jmh-core:1.26'
  64. testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.26'
  65. testImplementation 'com.google.guava:guava:30.0-jre'
  66. // prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.31 dependency
  67. // see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
  68. testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
  69. broken "org.apache.xmlgraphics:batik-script:${batikVersion}"
  70. javadocs project(':poi')
  71. javadocs project(':poi-scratchpad')
  72. }
  73. final String MODULE_NAME = 'org.apache.poi.ooxml'
  74. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  75. final Pattern MODULE_REGEX = ~'\\.jar$'
  76. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  77. 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")
  78. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  79. final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
  80. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  81. compileJava {
  82. dependsOn 'fixBatik'
  83. }
  84. task compileJava9(type: JavaCompile) {
  85. dependsOn 'compileJava', ':poi:jar'
  86. sourceCompatibility = 9
  87. targetCompatibility = 9
  88. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  89. source = file(JAVA9_SRC)
  90. classpath = files()
  91. options.compilerArgs = [
  92. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  93. '--module-path', files(MAIN_MODULE_PATH).asPath
  94. ]
  95. }
  96. task cacheJava9(type: Copy) {
  97. dependsOn 'compileJava9'
  98. from(file(JAVA9_OUT + VERSIONS9))
  99. into(JAVA9_SRC)
  100. }
  101. task compileTest9(type: JavaCompile) {
  102. dependsOn 'compileTestJava', ':poi:testJar'
  103. sourceCompatibility = 9
  104. targetCompatibility = 9
  105. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  106. source = file(TEST9_SRC)
  107. options.compilerArgs = [
  108. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  109. '--module-path', files(TEST_MODULE_PATH).asPath
  110. ]
  111. classpath = files()
  112. }
  113. task cacheTest9(type: Copy) {
  114. dependsOn 'compileTest9'
  115. from(file(TEST9_OUT + VERSIONS9))
  116. into(TEST9_SRC)
  117. }
  118. jar {
  119. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  120. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  121. into('META-INF/versions/9') {
  122. from JAVA9_SRC include '*.class'
  123. }
  124. }
  125. manifest {
  126. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  127. }
  128. }
  129. // Create a separate jar for test-code to depend on it in other projects
  130. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  131. task testJar(type: Jar, dependsOn: testClasses) {
  132. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  133. classifier 'tests'
  134. // ignore second module-info.class from main
  135. duplicatesStrategy = 'exclude'
  136. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  137. into('META-INF/versions/9') {
  138. from TEST9_SRC include '*.class'
  139. }
  140. }
  141. from sourceSets.test.output + sourceSets.main.output
  142. manifest {
  143. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  144. }
  145. }
  146. // based on https://github.com/moditect/moditect-gradle-plugin/issues/12
  147. task fixBatik(type: Zip) {
  148. ant.mkdir(dir: "${buildDir}/brokenJars")
  149. archiveFileName = "batik-script-${batikVersion}.jar"
  150. destinationDirectory = file("${buildDir}/brokenJars")
  151. from zipTree(configurations.broken.files.find{ f -> f.name.startsWith("batik-script") })
  152. filesMatching("**/org.apache.batik.script.InterpreterFactory") {
  153. it.filter{ it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
  154. }
  155. }
  156. javadoc {
  157. failOnError = true
  158. doFirst {
  159. options {
  160. if (JavaVersion.current().isJava9Compatible()) {
  161. addBooleanOption('html5', true)
  162. }
  163. links 'https://poi.apache.org/apidocs/dev/'
  164. links 'https://docs.oracle.com/javase/8/docs/api/'
  165. use = true
  166. splitIndex = true
  167. source = "1.8"
  168. classpath += configurations.javadocs.files
  169. }
  170. }
  171. }
  172. artifacts {
  173. tests testJar
  174. }
  175. test {
  176. // for some reason catching the OOM does not work when run from Gradle
  177. exclude '**/MemoryUsage.class'
  178. dependsOn { testJar }
  179. doFirst {
  180. jvmArgs += [
  181. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
  182. ]
  183. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  184. jvmArgs += [
  185. '--add-modules', MODULE_NAME,
  186. '--module-path', '../build/dist/maven/poi-ooxml-tests:' + files(TEST_MODULE_PATH).asPath,
  187. ]
  188. }
  189. }
  190. }
  191. publishing {
  192. publications {
  193. POI(MavenPublication) {
  194. pom {
  195. name = 'Apache POI - API based on OPC and OOXML schemas'
  196. description = 'Apache POI - Java API To Access Microsoft Format Files'
  197. }
  198. }
  199. }
  200. }