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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. 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. }
  26. test {
  27. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  28. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  29. }
  30. }
  31. }
  32. dependencies {
  33. api project(':poi')
  34. api project(path:':poi', configuration: 'archives')
  35. api "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  36. api "org.apache.commons:commons-math3:${commonsMathVersion}"
  37. api "commons-codec:commons-codec:${commonsCodecVersion}"
  38. testImplementation project(path: ':poi', configuration: 'tests')
  39. testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  40. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
  41. javadocs project(':poi')
  42. javadocs project(':poi-ooxml')
  43. }
  44. final MODULE_NAME = 'org.apache.poi.scratchpad'
  45. final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
  46. final Pattern MODULE_REGEX = ~'\\.jar$'
  47. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  48. final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  49. task compileJava9(type: JavaCompile) {
  50. dependsOn 'compileJava', ':poi:jar'
  51. sourceCompatibility = 9
  52. targetCompatibility = 9
  53. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  54. source = file(JAVA9_SRC)
  55. classpath = files()
  56. options.compilerArgs = [
  57. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
  58. '--module-path', files(MAIN_MODULE_PATH).asPath
  59. ]
  60. }
  61. task cacheJava9(type: Copy) {
  62. dependsOn 'compileJava9'
  63. from(file(JAVA9_OUT + VERSIONS9))
  64. into(JAVA9_SRC)
  65. }
  66. task compileTest9(type: JavaCompile) {
  67. dependsOn 'compileTestJava', ':poi:jar'
  68. sourceCompatibility = 9
  69. targetCompatibility = 9
  70. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  71. source = file(TEST9_SRC)
  72. options.compilerArgs = [
  73. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  74. '--module-path', files(TEST_MODULE_PATH).asPath
  75. ]
  76. classpath = files()
  77. }
  78. task cacheTest9(type: Copy) {
  79. dependsOn 'compileTest9'
  80. from(file(TEST9_OUT + VERSIONS9))
  81. into(TEST9_SRC)
  82. }
  83. jar {
  84. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  85. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  86. into('META-INF/versions/9') {
  87. from JAVA9_SRC include '*.class'
  88. }
  89. }
  90. manifest {
  91. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  92. }
  93. }
  94. // Create a separate jar for test-code to depend on it in other projects
  95. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  96. task testJar(type: Jar, dependsOn: testClasses) {
  97. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  98. classifier 'tests'
  99. // ignore second module-info.class from main
  100. duplicatesStrategy = 'exclude'
  101. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  102. into('META-INF/versions/9') {
  103. from TEST9_SRC include '*.class'
  104. }
  105. }
  106. from sourceSets.test.output + sourceSets.main.output
  107. manifest {
  108. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  109. }
  110. }
  111. javadoc {
  112. doFirst {
  113. options {
  114. classpath += configurations.javadocs.files
  115. }
  116. }
  117. }
  118. artifacts {
  119. tests testJar
  120. }
  121. test {
  122. dependsOn { testJar }
  123. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
  124. doFirst {
  125. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  126. jvmArgs += [
  127. '--add-modules', MODULE_NAME,
  128. '--module-path', '../build/dist/maven/poi-scratchpad-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
  129. ]
  130. }
  131. }
  132. }
  133. publishing {
  134. publications {
  135. POI(MavenPublication) {
  136. pom {
  137. name = 'Apache POI'
  138. description = 'Apache POI - Java API To Access Microsoft Format Files (Scratchpad)'
  139. }
  140. }
  141. }
  142. }