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

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