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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. }
  19. sourceSets {
  20. main {
  21. if (jdkVersion > 8) {
  22. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  23. }
  24. }
  25. test {
  26. if (jdkVersion > 8) {
  27. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  28. }
  29. }
  30. }
  31. dependencies {
  32. api 'org.apache.ant:ant:1.10.12'
  33. api project(':poi-ooxml')
  34. compileOnly project(path: ':poi-ooxml', configuration: 'archives')
  35. testImplementation project(path: ':poi-ooxml-lite-agent', configuration: 'archives')
  36. testImplementation project(path: ':poi', configuration: 'tests')
  37. testImplementation(project(path: ':poi-ooxml', configuration: 'tests')) {
  38. exclude group: 'org.apache.poi', module: 'poi-scratchpad'
  39. }
  40. testImplementation 'com.google.guava:guava:31.1-jre'
  41. testImplementation "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}"
  42. testImplementation 'org.slf4j:slf4j-simple:2.0.3'
  43. testRuntimeOnly "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
  44. if (SAXON_TEST) {
  45. testRuntimeOnly "net.sf.saxon:Saxon-HE:${saxonVersion}"
  46. }
  47. }
  48. final String MODULE_NAME = 'org.apache.poi.excelant'
  49. final Pattern MODULE_NOT_REGEX = ~'((poi|poi-ooxml|poi-scratchpad)[/\\\\][^/\\\\]+$|batik-script)'
  50. final Pattern MODULE_REGEX = ~'\\.jar$'
  51. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  52. final List TEST_MODULE_PATH = configurations.testRuntimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  53. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  54. final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
  55. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  56. task compileJava9(type: JavaCompile) {
  57. dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
  58. javaCompiler = javaToolchains.compilerFor {
  59. languageVersion = JavaLanguageVersion.of(jdkVersion >= 17 ? 17 : 11)
  60. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  61. }
  62. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  63. source = file(JAVA9_SRC)
  64. classpath = files()
  65. options.compilerArgs = [
  66. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  67. '--module-path', files(MAIN_MODULE_PATH).asPath
  68. ]
  69. onlyIf {
  70. jdkVersion > 8
  71. }
  72. }
  73. task cacheJava9(type: Copy) {
  74. dependsOn 'compileJava9'
  75. from(file(JAVA9_OUT + VERSIONS9))
  76. into(JAVA9_SRC)
  77. }
  78. task compileTest9(type: JavaCompile) {
  79. dependsOn 'compileTestJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
  80. javaCompiler = javaToolchains.compilerFor {
  81. languageVersion = JavaLanguageVersion.of(jdkVersion)
  82. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  83. }
  84. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  85. source = file(TEST9_SRC)
  86. options.compilerArgs = [
  87. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  88. '--module-path', files(TEST_MODULE_PATH).asPath
  89. ]
  90. classpath = files()
  91. onlyIf {
  92. jdkVersion > 8
  93. }
  94. }
  95. task cacheTest9(type: Copy) {
  96. dependsOn 'compileTest9'
  97. from(file(TEST9_OUT + VERSIONS9))
  98. into(TEST9_SRC)
  99. }
  100. jar {
  101. dependsOn cacheJava9
  102. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  103. if (jdkVersion == 8) {
  104. into('META-INF/versions/9') {
  105. from JAVA9_SRC include '*.class'
  106. }
  107. }
  108. manifest {
  109. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  110. }
  111. }
  112. javadocJar {
  113. metaInf {
  114. from("$projectDir/../legal/LICENSE")
  115. from("$projectDir/../legal/NOTICE")
  116. }
  117. }
  118. sourcesJar {
  119. metaInf {
  120. from("$projectDir/../legal/LICENSE")
  121. from("$projectDir/../legal/NOTICE")
  122. }
  123. }
  124. // Create a separate jar for test-code to depend on it in other projects
  125. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  126. task testJar(type: Jar, dependsOn: [ testClasses, cacheTest9 ] ) {
  127. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  128. classifier 'tests'
  129. // ignore second module-info.class from main
  130. duplicatesStrategy = 'exclude'
  131. if (jdkVersion == 8) {
  132. into('META-INF/versions/9') {
  133. from TEST9_SRC include '*.class'
  134. }
  135. }
  136. from sourceSets.test.output + sourceSets.main.output
  137. manifest {
  138. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  139. }
  140. }
  141. artifacts {
  142. tests testJar
  143. }
  144. test {
  145. dependsOn { testJar }
  146. doFirst {
  147. jvmArgs += [
  148. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
  149. ]
  150. if (jdkVersion > 8) {
  151. jvmArgs += [
  152. '--add-modules', MODULE_NAME,
  153. '--module-path', '../build/dist/maven/poi-excelant-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  154. ]
  155. }
  156. }
  157. }
  158. publishing {
  159. publications {
  160. POI(MavenPublication) {
  161. pom {
  162. name = 'Apache POI - ExcelAnt'
  163. description = 'Apache POI - Java API To Access Microsoft Format Files'
  164. }
  165. }
  166. }
  167. }