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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. plugins {
  17. id 'java'
  18. id 'maven-publish'
  19. id 'java-library'
  20. }
  21. final String JAVA9_SRC = 'src/main/java9'
  22. final String JAVA9_OUT = "${buildDir}/classes/java9/main/"
  23. final String TEST9_SRC = 'src/test/java9'
  24. final String TEST9_OUT = "${buildDir}/classes/java9/test/"
  25. final String VERSIONS9 = 'META-INF/versions/9'
  26. configurations {
  27. tests
  28. }
  29. sourceSets {
  30. main {
  31. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  32. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  33. }
  34. }
  35. test {
  36. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  37. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  38. }
  39. }
  40. }
  41. dependencies {
  42. api "commons-codec:commons-codec:${commonsCodecVersion}"
  43. api 'org.apache.commons:commons-collections4:4.4'
  44. api "org.apache.commons:commons-math3:${commonsMathVersion}"
  45. api 'com.zaxxer:SparseBitSet:1.2'
  46. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  47. implementation 'javax.activation:activation:1.1.1'
  48. testImplementation 'org.reflections:reflections:0.9.12'
  49. testImplementation 'org.apache.ant:ant:1.10.9'
  50. testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  51. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  52. }
  53. final String MODULE_NAME = 'org.apache.poi.poi'
  54. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  55. final Pattern MODULE_REGEX = ~'\\.jar$'
  56. final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  57. java {
  58. sourceCompatibility = JavaVersion.VERSION_1_8
  59. targetCompatibility = JavaVersion.VERSION_1_8
  60. withJavadocJar()
  61. withSourcesJar()
  62. }
  63. task compileJava9(type: JavaCompile) {
  64. dependsOn 'compileJava'
  65. sourceCompatibility = 9
  66. targetCompatibility = 9
  67. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  68. source = file(JAVA9_SRC)
  69. classpath = files()
  70. options.compilerArgs = [
  71. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  72. '--module-path', sourceSets.main.compileClasspath.asPath
  73. ]
  74. }
  75. task cacheJava9(type: Copy) {
  76. dependsOn 'compileJava9'
  77. from(file(JAVA9_OUT + VERSIONS9))
  78. into(JAVA9_SRC)
  79. }
  80. task compileTest9(type: JavaCompile) {
  81. dependsOn 'compileTestJava'
  82. sourceCompatibility = 9
  83. targetCompatibility = 9
  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(MODULE_PATH).asPath
  89. ]
  90. classpath = files()
  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 (JavaVersion.current() == JavaVersion.VERSION_1_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 (JavaVersion.current() == JavaVersion.VERSION_1_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. sourcesJar {
  126. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  127. exclude 'META-INF/services/**'
  128. }
  129. test {
  130. dependsOn 'testJar'
  131. useJUnitPlatform()
  132. doFirst {
  133. jvmArgs = [
  134. '-Djava.io.tmpdir=build',
  135. '-DPOI.testdata.path=../test-data',
  136. '-Djava.awt.headless=true',
  137. '-Djava.locale.providers=JRE,CLDR',
  138. '-Duser.language=en',
  139. '-Duser.country=US',
  140. '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
  141. "-Dversion.id=${project.version}",
  142. '-ea',
  143. '-Djunit.jupiter.execution.parallel.enabled=true',
  144. '-Djunit.jupiter.execution.parallel.config.strategy=fixed',
  145. '-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
  146. // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
  147. ]
  148. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  149. jvmArgs += [
  150. '-Dsun.reflect.debugModuleAccessChecks=true',
  151. '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
  152. '--illegal-access=warn',
  153. '--add-modules', MODULE_NAME,
  154. // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
  155. // opposed to the recommendation there, it doesn't work to add ... to the dependencies
  156. // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
  157. // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
  158. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
  159. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
  160. '--module-path', '../build/dist/maven/poi-tests:' + files(MODULE_PATH).asPath,
  161. ]
  162. }
  163. }
  164. }
  165. javadoc {
  166. // fails currently, need to fix the sources
  167. failOnError = false
  168. // if(JavaVersion.current().isJava9Compatible()) {
  169. // options.addBooleanOption('html5', true)
  170. // }
  171. }
  172. artifacts {
  173. tests testJar
  174. }
  175. publishing {
  176. publications {
  177. POI(MavenPublication) {
  178. artifactId project.archivesBaseName
  179. from components.java
  180. pom {
  181. name = 'Apache POI'
  182. description = 'Apache POI - Java API To Access Microsoft Format Files'
  183. }
  184. }
  185. }
  186. }
  187. generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"