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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. javadocs
  19. }
  20. sourceSets {
  21. main {
  22. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  23. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  24. }
  25. java {
  26. // also include the generated Version.java
  27. srcDirs += 'build/generated-sources'
  28. }
  29. }
  30. test {
  31. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  32. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  33. }
  34. }
  35. }
  36. dependencies {
  37. api "commons-codec:commons-codec:${commonsCodecVersion}"
  38. api 'org.apache.commons:commons-collections4:4.4'
  39. api "org.apache.commons:commons-math3:${commonsMathVersion}"
  40. api "commons-io:commons-io:${commonsIoVersion}"
  41. api 'com.zaxxer:SparseBitSet:1.2'
  42. api "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  43. // implementation 'javax.activation:activation:1.1.1'
  44. testImplementation 'org.reflections:reflections:0.10.2'
  45. testImplementation 'org.apache.ant:ant:1.10.12'
  46. testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  47. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  48. testImplementation 'org.apiguardian:apiguardian-api:1.1.2'
  49. // needed for locating the external references
  50. javadocs project(':poi-ooxml')
  51. javadocs project(':poi-scratchpad')
  52. }
  53. // generate and compile the file Version.java file
  54. task generateVersionJava() {
  55. //dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build'
  56. File fileIn = file("src/main/version/Version.java.template")
  57. File fileOut = file("build/generated-sources/org/apache/poi/Version.java")
  58. inputs.file fileIn
  59. outputs.file fileOut
  60. doLast {
  61. String content = fileIn.text
  62. content = content.replace("@VERSION@", version)
  63. content = content.replace("@DSTAMP@", new Date().format('yyyyMMdd'))
  64. fileOut.write content
  65. }
  66. }
  67. compileJava.dependsOn 'generateVersionJava'
  68. final String MODULE_NAME = 'org.apache.poi.poi'
  69. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  70. final Pattern MODULE_REGEX = ~'\\.jar$'
  71. final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  72. task compileJava9(type: JavaCompile) {
  73. dependsOn 'compileJava'
  74. sourceCompatibility = 9
  75. targetCompatibility = 9
  76. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  77. source = file(JAVA9_SRC)
  78. classpath = files()
  79. options.compilerArgs = [
  80. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  81. '--module-path', sourceSets.main.compileClasspath.asPath
  82. ]
  83. }
  84. task cacheJava9(type: Copy) {
  85. dependsOn 'compileJava9'
  86. from(file(JAVA9_OUT + VERSIONS9))
  87. into(JAVA9_SRC)
  88. }
  89. task compileTest9(type: JavaCompile) {
  90. dependsOn 'compileTestJava'
  91. sourceCompatibility = 9
  92. targetCompatibility = 9
  93. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  94. source = file(TEST9_SRC)
  95. options.compilerArgs = [
  96. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  97. '--module-path', files(MODULE_PATH).asPath
  98. ]
  99. classpath = files()
  100. }
  101. task cacheTest9(type: Copy) {
  102. dependsOn 'compileTest9'
  103. from(file(TEST9_OUT + VERSIONS9))
  104. into(TEST9_SRC)
  105. }
  106. jar {
  107. dependsOn cacheJava9
  108. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  109. into('META-INF/versions/9') {
  110. from JAVA9_SRC include '*.class'
  111. }
  112. }
  113. manifest {
  114. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  115. }
  116. }
  117. // Create a separate jar for test-code to depend on it in other projects
  118. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  119. task testJar(type: Jar, dependsOn: [ testClasses, cacheTest9 ]) {
  120. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  121. classifier 'tests'
  122. // ignore second module-info.class from main
  123. duplicatesStrategy = 'exclude'
  124. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  125. into('META-INF/versions/9') {
  126. from TEST9_SRC include '*.class'
  127. }
  128. }
  129. from sourceSets.test.output + sourceSets.main.output
  130. manifest {
  131. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  132. }
  133. }
  134. javadoc {
  135. dependsOn configurations.javadocs.dependencies.collect{ ':' + it.dependencyProject.name + ':compileJava' }
  136. doFirst {
  137. options {
  138. classpath += files(configurations.javadocs.dependencies.collect{ it.dependencyProject.sourceSets.main.output.classesDirs })
  139. }
  140. }
  141. }
  142. javadocJar {
  143. metaInf {
  144. from("$projectDir/../legal/LICENSE")
  145. from("$projectDir/../legal/NOTICE")
  146. }
  147. }
  148. sourcesJar {
  149. dependsOn generateVersionJava
  150. metaInf {
  151. from("$projectDir/../legal/LICENSE")
  152. from("$projectDir/../legal/NOTICE")
  153. }
  154. }
  155. artifacts {
  156. tests testJar
  157. }
  158. test {
  159. dependsOn { testJar }
  160. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  161. doFirst {
  162. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  163. jvmArgs << [
  164. '--add-modules', MODULE_NAME,
  165. '--module-path', '../build/dist/maven/poi-tests' + File.pathSeparator + files(MODULE_PATH).asPath,
  166. ]
  167. }
  168. }
  169. }
  170. publishing {
  171. publications {
  172. POI(MavenPublication) {
  173. pom {
  174. name = 'Apache POI - Common'
  175. description = 'Apache POI - Java API To Access Microsoft Format Files'
  176. }
  177. }
  178. }
  179. }