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

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