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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. if (!NO_SCRATCHPAD) {
  58. testImplementation project(':poi-scratchpad')
  59. testImplementation project(path:':poi-scratchpad', configuration:'tests')
  60. }
  61. testImplementation project(path:':poi', configuration:'tests')
  62. testImplementation project(path:':poi-ooxml-lite-agent', configuration: 'archives')
  63. testImplementation 'org.xmlunit:xmlunit-core:2.8.2'
  64. testImplementation 'org.reflections:reflections:0.9.12'
  65. testImplementation 'org.openjdk.jmh:jmh-core:1.32'
  66. testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.32'
  67. testImplementation 'com.google.guava:guava:30.1.1-jre'
  68. // prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.32 dependency
  69. // see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
  70. testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
  71. broken "org.apache.xmlgraphics:batik-script:${batikVersion}"
  72. javadocs project(':poi')
  73. javadocs project(':poi-scratchpad')
  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. compileJava {
  84. dependsOn 'fixBatik'
  85. }
  86. task compileJava9(type: JavaCompile) {
  87. dependsOn 'compileJava', ':poi:jar'
  88. sourceCompatibility = 9
  89. targetCompatibility = 9
  90. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  91. source = file(JAVA9_SRC)
  92. classpath = files()
  93. options.compilerArgs = [
  94. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  95. '--module-path', files(MAIN_MODULE_PATH).asPath
  96. ]
  97. }
  98. task cacheJava9(type: Copy) {
  99. dependsOn 'compileJava9'
  100. from(file(JAVA9_OUT + VERSIONS9))
  101. into(JAVA9_SRC)
  102. }
  103. task compileTest9(type: JavaCompile) {
  104. dependsOn 'compileTestJava', ':poi:testJar'
  105. sourceCompatibility = 9
  106. targetCompatibility = 9
  107. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  108. source = file(TEST9_SRC)
  109. options.compilerArgs = [
  110. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  111. '--module-path', files(TEST_MODULE_PATH).asPath
  112. ]
  113. classpath = files()
  114. }
  115. task cacheTest9(type: Copy) {
  116. dependsOn 'compileTest9'
  117. from(file(TEST9_OUT + VERSIONS9))
  118. into(TEST9_SRC)
  119. }
  120. jar {
  121. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  122. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  123. into('META-INF/versions/9') {
  124. from JAVA9_SRC include '*.class'
  125. }
  126. }
  127. manifest {
  128. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  129. }
  130. }
  131. // Create a separate jar for test-code to depend on it in other projects
  132. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  133. task testJar(type: Jar, dependsOn: testClasses) {
  134. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  135. classifier 'tests'
  136. // ignore second module-info.class from main
  137. duplicatesStrategy = 'exclude'
  138. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  139. into('META-INF/versions/9') {
  140. from TEST9_SRC include '*.class'
  141. }
  142. }
  143. from sourceSets.test.output + sourceSets.main.output
  144. manifest {
  145. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  146. }
  147. }
  148. // based on https://github.com/moditect/moditect-gradle-plugin/issues/12
  149. task fixBatik(type: Zip) {
  150. ant.mkdir(dir: "${buildDir}/brokenJars")
  151. archiveFileName = "batik-script-${batikVersion}.jar"
  152. destinationDirectory = file("${buildDir}/brokenJars")
  153. from zipTree(configurations.broken.files.find{ f -> f.name.startsWith("batik-script") })
  154. filesMatching("**/org.apache.batik.script.InterpreterFactory") {
  155. it.filter{ it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
  156. }
  157. }
  158. javadoc {
  159. failOnError = true
  160. doFirst {
  161. options {
  162. if (JavaVersion.current().isJava9Compatible()) {
  163. addBooleanOption('html5', true)
  164. }
  165. links 'https://poi.apache.org/apidocs/dev/'
  166. links 'https://docs.oracle.com/javase/8/docs/api/'
  167. use = true
  168. splitIndex = true
  169. source = "1.8"
  170. classpath += configurations.javadocs.files
  171. }
  172. }
  173. }
  174. artifacts {
  175. tests testJar
  176. }
  177. test {
  178. // for some reason catching the OOM does not work when run from Gradle
  179. exclude '**/MemoryUsage.class'
  180. dependsOn { testJar }
  181. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  182. if (NO_SCRATCHPAD) {
  183. useJUnitPlatform {
  184. excludeTags 'scratchpad.ignore'
  185. }
  186. }
  187. doFirst {
  188. jvmArgs += [
  189. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
  190. ]
  191. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  192. jvmArgs += [
  193. '--add-modules', MODULE_NAME,
  194. '--module-path', '../build/dist/maven/poi-ooxml-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  195. ]
  196. }
  197. }
  198. }
  199. publishing {
  200. publications {
  201. POI(MavenPublication) {
  202. pom {
  203. name = 'Apache POI - API based on OPC and OOXML schemas'
  204. description = 'Apache POI - Java API To Access Microsoft Format Files'
  205. }
  206. }
  207. }
  208. }