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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import java.util.regex.Pattern
  2. /* ====================================================================
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. ==================================================================== */
  16. configurations {
  17. tests
  18. javadocs
  19. }
  20. sourceSets {
  21. main {
  22. output.dir(JAVA9_OUT, builtBy: 'compileJava9')
  23. }
  24. test {
  25. output.dir(TEST9_OUT, builtBy: 'compileTest9')
  26. }
  27. }
  28. dependencies {
  29. api project(':poi')
  30. api project(path:':poi', configuration: 'archives')
  31. api "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  32. api "org.apache.commons:commons-math3:${commonsMathVersion}"
  33. api "commons-codec:commons-codec:${commonsCodecVersion}"
  34. testImplementation project(path: ':poi', configuration: 'tests')
  35. testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  36. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  37. testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
  38. if (SAXON_TEST) {
  39. testRuntimeOnly "net.sf.saxon:Saxon-HE:${saxonVersion}"
  40. }
  41. javadocs project(':poi')
  42. javadocs project(':poi-ooxml')
  43. }
  44. final MODULE_NAME = 'org.apache.poi.scratchpad'
  45. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|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 = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  49. task compileJava9(type: JavaCompile) {
  50. dependsOn 'compileJava', ':poi: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: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. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  81. manifest {
  82. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  83. }
  84. }
  85. // Create a separate jar for test-code to depend on it in other projects
  86. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  87. task testJar(type: Jar, dependsOn: testClasses) {
  88. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  89. classifier 'tests'
  90. // ignore second module-info.class from main
  91. duplicatesStrategy = 'exclude'
  92. from sourceSets.test.output + sourceSets.main.output
  93. manifest {
  94. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  95. }
  96. }
  97. javadoc {
  98. doFirst {
  99. options {
  100. classpath += configurations.javadocs.files
  101. }
  102. }
  103. }
  104. // without this dependency, parallel building sometimes fails because the javadoc
  105. // task tries to access a jar-file which is not yet fully built
  106. javadoc.mustRunAfter ':poi-ooxml:jar'
  107. javadocJar {
  108. metaInf {
  109. from("$projectDir/../legal/LICENSE")
  110. from("$projectDir/../legal/NOTICE")
  111. }
  112. }
  113. sourcesJar {
  114. metaInf {
  115. from("$projectDir/../legal/LICENSE")
  116. from("$projectDir/../legal/NOTICE")
  117. }
  118. }
  119. artifacts {
  120. tests testJar
  121. }
  122. test {
  123. dependsOn { testJar }
  124. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  125. doFirst {
  126. if (jdkVersion > 8) {
  127. jvmArgs += [
  128. '--add-modules', MODULE_NAME,
  129. '--module-path', '../build/dist/maven/poi-scratchpad-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  130. ]
  131. }
  132. }
  133. }
  134. publishing {
  135. publications {
  136. POI(MavenPublication) {
  137. pom {
  138. name = 'Apache POI'
  139. description = 'Apache POI - Java API To Access Microsoft Format Files (Scratchpad)'
  140. }
  141. }
  142. }
  143. }
  144. cyclonedxBom {
  145. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  146. includeConfigs = ["runtimeClasspath"]
  147. // skipConfigs is a list of configuration names to exclude when generating the BOM
  148. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  149. // Specified the type of project being built. Defaults to 'library'
  150. projectType = "library"
  151. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  152. schemaVersion = "1.4"
  153. // Boms destination directory (defaults to build/reports)
  154. destination = file("build/reports")
  155. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  156. outputName = "poi-scratchpad-${project.version}.bom"
  157. // The file format generated, can be xml, json or all for generating both
  158. outputFormat = "all"
  159. // Exclude BOM Serial Number
  160. includeBomSerialNumber = true
  161. }