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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. exclude group: 'xml-apis', module: 'xml-apis'
  20. }
  21. compileClasspath {
  22. exclude group: 'xalan', module: 'xalan'
  23. exclude group: 'xml-apis', module: 'xml-apis'
  24. }
  25. broken
  26. tests
  27. javadocs
  28. }
  29. sourceSets {
  30. main {
  31. output.dir(JAVA9_OUT, builtBy: 'compileJava9')
  32. }
  33. test {
  34. output.dir(TEST9_OUT, builtBy: 'compileTest9')
  35. }
  36. }
  37. java {
  38. registerFeature('signing') {
  39. usingSourceSet(sourceSets.main)
  40. }
  41. registerFeature('render') {
  42. usingSourceSet(sourceSets.main)
  43. }
  44. registerFeature('rendersign') {
  45. usingSourceSet(sourceSets.main)
  46. }
  47. }
  48. dependencies {
  49. api project(':poi')
  50. api project(':poi-ooxml-full')
  51. api project(path: ':poi-ooxml-full', configuration: 'archives')
  52. api "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  53. api "org.apache.commons:commons-compress:${commonsCompressVersion}"
  54. api "commons-io:commons-io:${commonsIoVersion}"
  55. api 'com.github.virtuald:curvesapi:1.07'
  56. api "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  57. api 'org.apache.commons:commons-collections4:4.4'
  58. signingImplementation 'org.apache.santuario:xmlsec:3.0.1'
  59. signingImplementation "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  60. signingImplementation "org.bouncycastle:bcutil-jdk15on:${bouncyCastleVersion}"
  61. rendersignImplementation 'org.apache.santuario:xmlsec:3.0.1'
  62. rendersignImplementation "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  63. rendersignImplementation "org.bouncycastle:bcutil-jdk15on:${bouncyCastleVersion}"
  64. renderImplementation "org.apache.pdfbox:pdfbox:${pdfboxVersion}"
  65. renderImplementation "de.rototor.pdfbox:graphics2d:${graphics2dVersion}"
  66. renderImplementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}"
  67. renderImplementation("org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}") {
  68. exclude group: 'xalan', module: 'xalan'
  69. exclude group: 'xml-apis', module: 'xml-apis'
  70. }
  71. renderImplementation("org.apache.xmlgraphics:batik-codec:${batikVersion}") {
  72. exclude group: 'xalan', module: 'xalan'
  73. exclude group: 'xml-apis', module: 'xml-apis'
  74. }
  75. renderImplementation("org.apache.xmlgraphics:batik-bridge:${batikVersion}") {
  76. exclude group: 'xalan', module: 'xalan'
  77. exclude group: 'xml-apis', module: 'xml-apis'
  78. }
  79. rendersignImplementation "org.apache.pdfbox:pdfbox:${pdfboxVersion}"
  80. rendersignImplementation "de.rototor.pdfbox:graphics2d:${graphics2dVersion}"
  81. rendersignImplementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}"
  82. rendersignImplementation("org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}") {
  83. exclude group: 'xalan', module: 'xalan'
  84. exclude group: 'xml-apis', module: 'xml-apis'
  85. }
  86. rendersignImplementation("org.apache.xmlgraphics:batik-codec:${batikVersion}") {
  87. exclude group: 'xalan', module: 'xalan'
  88. exclude group: 'xml-apis', module: 'xml-apis'
  89. }
  90. rendersignImplementation("org.apache.xmlgraphics:batik-bridge:${batikVersion}") {
  91. exclude group: 'xalan', module: 'xalan'
  92. exclude group: 'xml-apis', module: 'xml-apis'
  93. }
  94. if (!NO_SCRATCHPAD) {
  95. testImplementation project(':poi-scratchpad')
  96. testImplementation project(path:':poi-scratchpad', configuration:'tests')
  97. }
  98. testImplementation project(path:':poi', configuration:'tests')
  99. testImplementation project(path:':poi-ooxml-lite-agent', configuration: 'archives')
  100. testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
  101. testImplementation 'org.xmlunit:xmlunit-core:2.9.0'
  102. testImplementation 'org.reflections:reflections:0.10.2'
  103. testImplementation 'org.openjdk.jmh:jmh-core:1.36'
  104. testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.36'
  105. testImplementation 'com.google.guava:guava:31.1-jre'
  106. testImplementation 'org.tukaani:xz:1.9'
  107. testImplementation 'com.github.rzymek:opczip:1.2.0'
  108. // prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.x dependency
  109. // see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
  110. testImplementation "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}"
  111. testImplementation 'org.slf4j:slf4j-simple:2.0.6'
  112. broken("org.apache.xmlgraphics:batik-script:${batikVersion}"){
  113. exclude group: 'xalan', module: 'xalan'
  114. exclude group: 'xml-apis', module: 'xml-apis'
  115. }
  116. javadocs project(':poi')
  117. javadocs project(':poi-scratchpad')
  118. }
  119. final String MODULE_NAME = 'org.apache.poi.ooxml'
  120. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  121. final Pattern MODULE_REGEX = ~'\\.jar$'
  122. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  123. 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")
  124. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  125. final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
  126. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  127. compileJava {
  128. dependsOn 'fixBatik', 'cleanupBatik'
  129. }
  130. task compileJava9(type: JavaCompile) {
  131. dependsOn 'compileJava', ':poi:jar'
  132. javaCompiler = javaToolchains.compilerFor {
  133. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  134. }
  135. sourceCompatibility = 1.9
  136. targetCompatibility = 1.9
  137. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  138. source = file(JAVA9_SRC)
  139. classpath = files()
  140. options.compilerArgs = [
  141. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  142. '--module-path', files(MAIN_MODULE_PATH).asPath
  143. ]
  144. }
  145. task compileTest9(type: JavaCompile) {
  146. dependsOn 'compileTestJava', ':poi:testJar'
  147. javaCompiler = javaToolchains.compilerFor {
  148. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  149. }
  150. sourceCompatibility = 1.9
  151. targetCompatibility = 1.9
  152. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  153. source = file(TEST9_SRC)
  154. options.compilerArgs = [
  155. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  156. '--module-path', files(TEST_MODULE_PATH).asPath
  157. ]
  158. classpath = files()
  159. }
  160. jar {
  161. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  162. manifest {
  163. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  164. }
  165. }
  166. // Create a separate jar for test-code to depend on it in other projects
  167. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  168. task testJar(type: Jar, dependsOn: testClasses) {
  169. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  170. classifier 'tests'
  171. // ignore second module-info.class from main
  172. duplicatesStrategy = 'exclude'
  173. from sourceSets.test.output + sourceSets.main.output
  174. manifest {
  175. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  176. }
  177. }
  178. // based on https://github.com/moditect/moditect-gradle-plugin/issues/12
  179. task fixBatik(type: Zip) {
  180. ant.mkdir(dir: "${buildDir}/brokenJars")
  181. archiveFileName = "batik-script-${batikVersion}.jar"
  182. destinationDirectory = file("${buildDir}/brokenJars")
  183. from zipTree(configurations.broken.files.find{ f -> f.name.startsWith("batik-script") })
  184. filesMatching("**/org.apache.batik.script.InterpreterFactory") {
  185. it.filter{ it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
  186. }
  187. }
  188. task cleanupBatik(type: Delete) {
  189. // remove older files to avoid build failures because of duplicate modules
  190. delete fileTree("${buildDir}/brokenJars/").matching {
  191. include "*.jar"
  192. exclude "batik*-${batikVersion}.jar"
  193. }
  194. }
  195. javadoc {
  196. failOnError = true
  197. doFirst {
  198. options {
  199. if (JavaVersion.current().isJava9Compatible()) {
  200. addBooleanOption('html5', true)
  201. }
  202. links 'https://poi.apache.org/apidocs/dev/'
  203. links 'https://docs.oracle.com/javase/8/docs/api/'
  204. use = true
  205. splitIndex = true
  206. source = "1.8"
  207. classpath += configurations.javadocs.files
  208. }
  209. }
  210. }
  211. javadocJar {
  212. metaInf {
  213. from("$projectDir/../legal/LICENSE")
  214. from("$projectDir/../legal/NOTICE")
  215. }
  216. }
  217. sourcesJar {
  218. metaInf {
  219. from("$projectDir/../legal/LICENSE")
  220. from("$projectDir/../legal/NOTICE")
  221. }
  222. }
  223. artifacts {
  224. tests testJar
  225. }
  226. test {
  227. // for some reason catching the OOM does not work when run from Gradle
  228. exclude '**/MemoryUsage.class'
  229. dependsOn { testJar }
  230. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  231. if (NO_SCRATCHPAD) {
  232. useJUnitPlatform {
  233. excludeTags 'scratchpad.ignore'
  234. }
  235. }
  236. doFirst {
  237. jvmArgs += [
  238. "-Xverify:all",
  239. "-XX:ErrorFile=../build/hs_err_pid%p.log",
  240. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}"
  241. ]
  242. if (jdkVersion > 8) {
  243. jvmArgs += [
  244. '--add-modules', MODULE_NAME,
  245. '--module-path', '../build/dist/maven/poi-ooxml-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  246. ]
  247. }
  248. }
  249. }
  250. publishing {
  251. publications {
  252. POI(MavenPublication) {
  253. pom {
  254. name = 'Apache POI - API based on OPC and OOXML schemas'
  255. description = 'Apache POI - Java API To Access Microsoft Format Files'
  256. }
  257. suppressPomMetadataWarningsFor('renderApiElements')
  258. suppressPomMetadataWarningsFor('renderRuntimeElements')
  259. suppressPomMetadataWarningsFor('signingApiElements')
  260. suppressPomMetadataWarningsFor('signingRuntimeElements')
  261. suppressPomMetadataWarningsFor('rendersignApiElements')
  262. suppressPomMetadataWarningsFor('rendersignRuntimeElements')
  263. }
  264. }
  265. }
  266. cyclonedxBom {
  267. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  268. includeConfigs = ["runtimeClasspath"]
  269. // skipConfigs is a list of configuration names to exclude when generating the BOM
  270. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  271. // Specified the type of project being built. Defaults to 'library'
  272. projectType = "library"
  273. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  274. schemaVersion = "1.4"
  275. // Boms destination directory (defaults to build/reports)
  276. destination = file("build/reports")
  277. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  278. outputName = "poi-ooxml-${project.version}.bom"
  279. // The file format generated, can be xml, json or all for generating both
  280. outputFormat = "all"
  281. // Exclude BOM Serial Number
  282. includeBomSerialNumber = true
  283. }