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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  23. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  24. }
  25. }
  26. test {
  27. if (JavaVersion.current() != JavaVersion.VERSION_1_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. sourceCompatibility = 9
  56. targetCompatibility = 9
  57. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  58. source = file(JAVA9_SRC)
  59. classpath = files()
  60. options.compilerArgs = [
  61. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  62. '--module-path', files(MAIN_MODULE_PATH).asPath
  63. ]
  64. }
  65. task cacheJava9(type: Copy) {
  66. dependsOn 'compileJava9'
  67. from(file(JAVA9_OUT + VERSIONS9))
  68. into(JAVA9_SRC)
  69. }
  70. task compileTest9(type: JavaCompile) {
  71. dependsOn 'compileTestJava', ':poi:jar'
  72. sourceCompatibility = 9
  73. targetCompatibility = 9
  74. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  75. source = file(TEST9_SRC)
  76. options.compilerArgs = [
  77. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  78. '--module-path', files(TEST_MODULE_PATH).asPath
  79. ]
  80. classpath = files()
  81. }
  82. task cacheTest9(type: Copy) {
  83. dependsOn 'compileTest9'
  84. from(file(TEST9_OUT + VERSIONS9))
  85. into(TEST9_SRC)
  86. }
  87. jar {
  88. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  89. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  90. into('META-INF/versions/9') {
  91. from JAVA9_SRC include '*.class'
  92. }
  93. }
  94. manifest {
  95. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  96. }
  97. }
  98. // Create a separate jar for test-code to depend on it in other projects
  99. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  100. task testJar(type: Jar, dependsOn: testClasses) {
  101. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  102. classifier 'tests'
  103. // ignore second module-info.class from main
  104. duplicatesStrategy = 'exclude'
  105. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  106. into('META-INF/versions/9') {
  107. from TEST9_SRC include '*.class'
  108. }
  109. }
  110. from sourceSets.test.output + sourceSets.main.output
  111. manifest {
  112. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  113. }
  114. }
  115. javadoc {
  116. doFirst {
  117. options {
  118. classpath += configurations.javadocs.files
  119. }
  120. }
  121. }
  122. // without this dependency, parallel building sometimes fails because the javadoc
  123. // task tries to access a jar-file which is not yet fully built
  124. javadoc.mustRunAfter ':poi-ooxml:jar'
  125. javadocJar {
  126. metaInf {
  127. from("$projectDir/../legal/LICENSE")
  128. from("$projectDir/../legal/NOTICE")
  129. }
  130. }
  131. sourcesJar {
  132. metaInf {
  133. from("$projectDir/../legal/LICENSE")
  134. from("$projectDir/../legal/NOTICE")
  135. }
  136. }
  137. artifacts {
  138. tests testJar
  139. }
  140. test {
  141. dependsOn { testJar }
  142. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  143. doFirst {
  144. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  145. jvmArgs += [
  146. '--add-modules', MODULE_NAME,
  147. '--module-path', '../build/dist/maven/poi-scratchpad-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  148. ]
  149. }
  150. }
  151. }
  152. publishing {
  153. publications {
  154. POI(MavenPublication) {
  155. pom {
  156. name = 'Apache POI'
  157. description = 'Apache POI - Java API To Access Microsoft Format Files (Scratchpad)'
  158. }
  159. }
  160. }
  161. }