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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. tests
  18. }
  19. sourceSets {
  20. main {
  21. if (jdkVersion > 8) {
  22. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  23. }
  24. }
  25. test {
  26. if (jdkVersion > 8) {
  27. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  28. }
  29. }
  30. }
  31. dependencies {
  32. api 'org.apache.ant:ant:1.10.12'
  33. api project(':poi-ooxml')
  34. compileOnly project(path: ':poi-ooxml', configuration: 'archives')
  35. testImplementation project(path: ':poi-ooxml-lite-agent', configuration: 'archives')
  36. testImplementation project(path: ':poi', configuration: 'tests')
  37. testImplementation(project(path: ':poi-ooxml', configuration: 'tests')) {
  38. exclude group: 'org.apache.poi', module: 'poi-scratchpad'
  39. }
  40. testImplementation 'com.google.guava:guava:31.1-jre'
  41. testImplementation "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}"
  42. testImplementation 'org.slf4j:slf4j-simple:2.0.6'
  43. testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
  44. if (SAXON_TEST) {
  45. testRuntimeOnly "net.sf.saxon:Saxon-HE:${saxonVersion}"
  46. }
  47. }
  48. final String MODULE_NAME = 'org.apache.poi.excelant'
  49. final Pattern MODULE_NOT_REGEX = ~'((poi|poi-ooxml|poi-scratchpad)[/\\\\][^/\\\\]+$|batik-script)'
  50. final Pattern MODULE_REGEX = ~'\\.jar$'
  51. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  52. final List TEST_MODULE_PATH = configurations.testRuntimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  53. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  54. final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
  55. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  56. task compileJava9(type: JavaCompile) {
  57. dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
  58. javaCompiler = javaToolchains.compilerFor {
  59. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  60. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  61. }
  62. sourceCompatibility = 1.9
  63. targetCompatibility = 1.9
  64. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  65. source = file(JAVA9_SRC)
  66. classpath = files()
  67. options.compilerArgs = [
  68. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  69. '--module-path', files(MAIN_MODULE_PATH).asPath
  70. ]
  71. }
  72. task cacheJava9(type: Copy) {
  73. dependsOn 'compileJava9'
  74. from(file(JAVA9_OUT + VERSIONS9))
  75. into(JAVA9_SRC)
  76. }
  77. task compileTest9(type: JavaCompile) {
  78. dependsOn 'compileTestJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
  79. javaCompiler = javaToolchains.compilerFor {
  80. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  81. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  82. }
  83. sourceCompatibility = 1.9
  84. targetCompatibility = 1.9
  85. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  86. source = file(TEST9_SRC)
  87. options.compilerArgs = [
  88. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  89. '--module-path', files(TEST_MODULE_PATH).asPath
  90. ]
  91. classpath = files()
  92. }
  93. task cacheTest9(type: Copy) {
  94. dependsOn 'compileTest9'
  95. from(file(TEST9_OUT + VERSIONS9))
  96. into(TEST9_SRC)
  97. }
  98. jar {
  99. dependsOn cacheJava9, cyclonedxBom
  100. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  101. if (jdkVersion == 8) {
  102. into('META-INF/versions/9') {
  103. from JAVA9_SRC include '*.class'
  104. }
  105. }
  106. manifest {
  107. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  108. }
  109. }
  110. javadocJar {
  111. metaInf {
  112. from("$projectDir/../legal/LICENSE")
  113. from("$projectDir/../legal/NOTICE")
  114. }
  115. }
  116. sourcesJar {
  117. metaInf {
  118. from("$projectDir/../legal/LICENSE")
  119. from("$projectDir/../legal/NOTICE")
  120. }
  121. }
  122. // Create a separate jar for test-code to depend on it in other projects
  123. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  124. task testJar(type: Jar, dependsOn: [ testClasses, cacheTest9 ] ) {
  125. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  126. classifier 'tests'
  127. // ignore second module-info.class from main
  128. duplicatesStrategy = 'exclude'
  129. if (jdkVersion == 8) {
  130. into('META-INF/versions/9') {
  131. from TEST9_SRC include '*.class'
  132. }
  133. }
  134. from sourceSets.test.output + sourceSets.main.output
  135. manifest {
  136. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  137. }
  138. }
  139. artifacts {
  140. tests testJar
  141. }
  142. test {
  143. dependsOn { testJar }
  144. doFirst {
  145. jvmArgs += [
  146. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
  147. ]
  148. if (jdkVersion > 8) {
  149. jvmArgs += [
  150. '--add-modules', MODULE_NAME,
  151. '--module-path', '../build/dist/maven/poi-excelant-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  152. ]
  153. }
  154. }
  155. }
  156. publishing {
  157. publications {
  158. POI(MavenPublication) {
  159. pom {
  160. name = 'Apache POI - ExcelAnt'
  161. description = 'Apache POI - Java API To Access Microsoft Format Files'
  162. }
  163. }
  164. }
  165. }
  166. cyclonedxBom {
  167. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  168. includeConfigs = ["runtimeClasspath"]
  169. // skipConfigs is a list of configuration names to exclude when generating the BOM
  170. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  171. // Specified the type of project being built. Defaults to 'library'
  172. projectType = "library"
  173. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  174. schemaVersion = "1.4"
  175. // Boms destination directory (defaults to build/reports)
  176. destination = file("build/reports")
  177. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  178. outputName = "poi-excelant-${project.version}.bom"
  179. // The file format generated, can be xml, json or all for generating both
  180. outputFormat = "all"
  181. // Exclude BOM Serial Number
  182. includeBomSerialNumber = true
  183. }