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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. javadocs
  29. }
  30. sourceSets {
  31. main {
  32. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  33. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  34. }
  35. }
  36. test {
  37. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  38. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  39. }
  40. }
  41. }
  42. dependencies {
  43. api "commons-codec:commons-codec:${commonsCodecVersion}"
  44. api 'org.apache.commons:commons-collections4:4.4'
  45. api "org.apache.commons:commons-math3:${commonsMathVersion}"
  46. api 'com.zaxxer:SparseBitSet:1.2'
  47. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  48. implementation 'javax.activation:activation:1.1.1'
  49. testImplementation 'org.reflections:reflections:0.9.12'
  50. testImplementation 'org.apache.ant:ant:1.10.9'
  51. testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  52. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  53. javadocs project(':poi-ooxml')
  54. javadocs project(':poi-scratchpad')
  55. }
  56. final String MODULE_NAME = 'org.apache.poi.poi'
  57. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  58. final Pattern MODULE_REGEX = ~'\\.jar$'
  59. final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  60. java {
  61. sourceCompatibility = JavaVersion.VERSION_1_8
  62. targetCompatibility = JavaVersion.VERSION_1_8
  63. withJavadocJar()
  64. withSourcesJar()
  65. }
  66. task compileJava9(type: JavaCompile) {
  67. dependsOn 'compileJava'
  68. sourceCompatibility = 9
  69. targetCompatibility = 9
  70. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  71. source = file(JAVA9_SRC)
  72. classpath = files()
  73. options.compilerArgs = [
  74. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  75. '--module-path', sourceSets.main.compileClasspath.asPath
  76. ]
  77. }
  78. task cacheJava9(type: Copy) {
  79. dependsOn 'compileJava9'
  80. from(file(JAVA9_OUT + VERSIONS9))
  81. into(JAVA9_SRC)
  82. }
  83. task compileTest9(type: JavaCompile) {
  84. dependsOn 'compileTestJava'
  85. sourceCompatibility = 9
  86. targetCompatibility = 9
  87. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  88. source = file(TEST9_SRC)
  89. options.compilerArgs = [
  90. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  91. '--module-path', files(MODULE_PATH).asPath
  92. ]
  93. classpath = files()
  94. }
  95. task cacheTest9(type: Copy) {
  96. dependsOn 'compileTest9'
  97. from(file(TEST9_OUT + VERSIONS9))
  98. into(TEST9_SRC)
  99. }
  100. jar {
  101. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  102. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  103. into('META-INF/versions/9') {
  104. from JAVA9_SRC include '*.class'
  105. }
  106. }
  107. manifest {
  108. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  109. }
  110. }
  111. // Create a separate jar for test-code to depend on it in other projects
  112. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  113. task testJar(type: Jar, dependsOn: testClasses) {
  114. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  115. classifier 'tests'
  116. // ignore second module-info.class from main
  117. duplicatesStrategy = 'exclude'
  118. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  119. into('META-INF/versions/9') {
  120. from TEST9_SRC include '*.class'
  121. }
  122. }
  123. from sourceSets.test.output + sourceSets.main.output
  124. manifest {
  125. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  126. }
  127. }
  128. sourcesJar {
  129. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  130. exclude 'META-INF/services/**'
  131. }
  132. javadoc {
  133. failOnError = true
  134. doFirst {
  135. options {
  136. if (JavaVersion.current().isJava9Compatible()) {
  137. addBooleanOption('html5', true)
  138. }
  139. links 'https://poi.apache.org/apidocs/dev/'
  140. links 'https://docs.oracle.com/javase/8/docs/api/'
  141. use = true
  142. splitIndex = true
  143. source = "1.8"
  144. classpath += configurations.javadocs.files
  145. }
  146. }
  147. }
  148. artifacts {
  149. tests testJar
  150. }
  151. test {
  152. dependsOn { testJar }
  153. useJUnitPlatform()
  154. doFirst {
  155. jvmArgs = [
  156. '-Djava.io.tmpdir=build',
  157. '-DPOI.testdata.path=../test-data',
  158. '-Djava.awt.headless=true',
  159. '-Djava.locale.providers=JRE,CLDR',
  160. '-Duser.language=en',
  161. '-Duser.country=US',
  162. '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
  163. "-Dversion.id=${project.version}",
  164. '-ea',
  165. '-Djunit.jupiter.execution.parallel.enabled=true',
  166. '-Djunit.jupiter.execution.parallel.config.strategy=fixed',
  167. '-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
  168. // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
  169. ]
  170. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  171. jvmArgs += [
  172. '-Dsun.reflect.debugModuleAccessChecks=true',
  173. '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
  174. '--illegal-access=warn',
  175. '--add-modules', MODULE_NAME,
  176. // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
  177. // opposed to the recommendation there, it doesn't work to add ... to the dependencies
  178. // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
  179. // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
  180. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
  181. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
  182. '--module-path', '../build/dist/maven/poi-tests:' + files(MODULE_PATH).asPath,
  183. ]
  184. }
  185. }
  186. }
  187. publishing {
  188. publications {
  189. POI(MavenPublication) {
  190. artifactId project.archivesBaseName
  191. from components.java
  192. pom {
  193. name = 'Apache POI'
  194. description = 'Apache POI - Java API To Access Microsoft Format Files'
  195. }
  196. }
  197. }
  198. }
  199. generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"