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

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