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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. javadocs
  19. }
  20. sourceSets {
  21. main {
  22. output.dir(JAVA9_OUT, builtBy: 'compileJava9')
  23. java {
  24. // also include the generated Version.java
  25. srcDirs += 'build/generated-sources'
  26. }
  27. }
  28. test {
  29. output.dir(TEST9_OUT, builtBy: 'compileTest9')
  30. }
  31. }
  32. dependencies {
  33. api "commons-codec:commons-codec:${commonsCodecVersion}"
  34. api 'org.apache.commons:commons-collections4:4.4'
  35. api "org.apache.commons:commons-math3:${commonsMathVersion}"
  36. api "commons-io:commons-io:${commonsIoVersion}"
  37. api 'com.zaxxer:SparseBitSet:1.2'
  38. api "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  39. testImplementation 'org.reflections:reflections:0.10.2'
  40. testImplementation 'org.apache.ant:ant:1.10.12'
  41. testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  42. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  43. testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
  44. if (SAXON_TEST) {
  45. testRuntimeOnly "net.sf.saxon:Saxon-HE:${saxonVersion}"
  46. }
  47. // needed for locating the external references
  48. javadocs project(':poi-ooxml')
  49. javadocs project(':poi-scratchpad')
  50. }
  51. // generate and compile the file Version.java file
  52. task generateVersionJava() {
  53. //dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build'
  54. File fileIn = file("src/main/version/Version.java.template")
  55. File fileOut = file("build/generated-sources/org/apache/poi/Version.java")
  56. inputs.file fileIn
  57. outputs.file fileOut
  58. doLast {
  59. String content = fileIn.text
  60. content = content.replace("@VERSION@", version)
  61. content = content.replace("@DSTAMP@", new Date().format('yyyyMMdd'))
  62. fileOut.write content
  63. }
  64. }
  65. compileJava.dependsOn 'generateVersionJava'
  66. final String MODULE_NAME = 'org.apache.poi.poi'
  67. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  68. final Pattern MODULE_REGEX = ~'\\.jar$'
  69. final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  70. task compileJava9(type: JavaCompile) {
  71. dependsOn 'compileJava'
  72. javaCompiler = javaToolchains.compilerFor {
  73. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  74. }
  75. sourceCompatibility = 1.9
  76. targetCompatibility = 1.9
  77. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  78. source = file(JAVA9_SRC)
  79. classpath = files()
  80. options.compilerArgs = [
  81. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  82. '--module-path', sourceSets.main.compileClasspath.asPath
  83. ]
  84. }
  85. task compileTest9(type: JavaCompile) {
  86. dependsOn 'compileTestJava'
  87. javaCompiler = javaToolchains.compilerFor {
  88. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  89. }
  90. sourceCompatibility = 1.9
  91. targetCompatibility = 1.9
  92. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  93. source = file(TEST9_SRC)
  94. options.compilerArgs = [
  95. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  96. '--module-path', files(MODULE_PATH).asPath
  97. ]
  98. classpath = files()
  99. }
  100. jar {
  101. dependsOn compileJava9
  102. manifest {
  103. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  104. }
  105. }
  106. // Create a separate jar for test-code to depend on it in other projects
  107. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  108. task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ]) {
  109. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  110. classifier 'tests'
  111. // ignore second module-info.class from main
  112. duplicatesStrategy = 'exclude'
  113. from sourceSets.test.output + sourceSets.main.output
  114. manifest {
  115. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  116. }
  117. }
  118. javadoc {
  119. dependsOn configurations.javadocs.dependencies.collect{ ':' + it.dependencyProject.name + ':compileJava' }
  120. doFirst {
  121. options {
  122. classpath += files(configurations.javadocs.dependencies.collect{ it.dependencyProject.sourceSets.main.output.classesDirs })
  123. }
  124. }
  125. }
  126. javadocJar {
  127. metaInf {
  128. from("$projectDir/../legal/LICENSE")
  129. from("$projectDir/../legal/NOTICE")
  130. }
  131. }
  132. sourcesJar {
  133. dependsOn generateVersionJava
  134. metaInf {
  135. from("$projectDir/../legal/LICENSE")
  136. from("$projectDir/../legal/NOTICE")
  137. }
  138. }
  139. artifacts {
  140. tests testJar
  141. }
  142. test {
  143. dependsOn { testJar }
  144. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  145. doFirst {
  146. if (jdkVersion > 8) {
  147. jvmArgs << [
  148. '--add-modules', MODULE_NAME,
  149. '--module-path', '../build/dist/maven/poi-tests' + File.pathSeparator + files(MODULE_PATH).asPath,
  150. ]
  151. }
  152. }
  153. }
  154. publishing {
  155. publications {
  156. POI(MavenPublication) {
  157. pom {
  158. name = 'Apache POI - Common'
  159. description = 'Apache POI - Java API To Access Microsoft Format Files'
  160. }
  161. }
  162. }
  163. }
  164. cyclonedxBom {
  165. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  166. includeConfigs = ["runtimeClasspath"]
  167. // skipConfigs is a list of configuration names to exclude when generating the BOM
  168. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  169. // Specified the type of project being built. Defaults to 'library'
  170. projectType = "library"
  171. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  172. schemaVersion = "1.4"
  173. // Boms destination directory (defaults to build/reports)
  174. destination = file("build/reports")
  175. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  176. outputName = "poi-${project.version}.bom"
  177. // The file format generated, can be xml, json or all for generating both
  178. outputFormat = "all"
  179. // Exclude BOM Serial Number
  180. includeBomSerialNumber = true
  181. }