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

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