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

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