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

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