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

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