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

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