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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. buildscript {
  16. repositories {
  17. maven { url "https://plugins.gradle.org/m2/" }
  18. }
  19. dependencies {
  20. // 2.x fails with "Could not get unknown property 'me'"
  21. classpath 'me.champeau.gradle:japicmp-gradle-plugin:0.1.2'
  22. classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0"
  23. }
  24. }
  25. repositories {
  26. mavenCentral()
  27. }
  28. // Only add the plugin for Sonar if enabled
  29. if (project.hasProperty('enableSonar')) {
  30. println 'Enabling Sonar support'
  31. apply plugin: "org.sonarqube"
  32. }
  33. // For help converting an Ant build to a Gradle build, see
  34. // https://docs.gradle.org/current/userguide/ant.html
  35. configurations {
  36. antLibs {
  37. attributes {
  38. attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
  39. }
  40. }
  41. }
  42. dependencies {
  43. antLibs("org.junit.jupiter:junit-jupiter:5.7.0")
  44. antLibs("org.apache.ant:ant-junitlauncher:1.10.9")
  45. }
  46. ant.taskdef(name: "junit",
  47. classname: "org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.JUnitLauncherTask",
  48. classpath: configurations.antLibs.asPath)
  49. wrapper {
  50. gradleVersion = '6.5'
  51. }
  52. task adjustWrapperPropertiesFile {
  53. doLast {
  54. ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) {
  55. fileset(dir: project.projectDir, includes: 'gradle/wrapper/gradle-wrapper.properties')
  56. }
  57. new File(project.projectDir, 'gradle/wrapper/gradle-wrapper.properties').with { it.text = it.readLines().findAll { it }.sort().join('\n') }
  58. ant.fixcrlf(file: 'gradle/wrapper/gradle-wrapper.properties', eol: 'lf')
  59. }
  60. }
  61. wrapper.finalizedBy adjustWrapperPropertiesFile
  62. // helper method to download a jar file manually from an URL, e.g. XMLBeans 4.0.0
  63. def urlFile = { url, name ->
  64. File file = new File("$buildDir/download/${name}.jar")
  65. file.parentFile.mkdirs()
  66. if (!file.exists()) {
  67. new URL(url).withInputStream { downloadStream ->
  68. file.withOutputStream { fileOut ->
  69. fileOut << downloadStream
  70. }
  71. }
  72. }
  73. files(file.absolutePath)
  74. }
  75. /**
  76. Define properties for all projects, including this one
  77. */
  78. allprojects {
  79. apply plugin: 'eclipse'
  80. }
  81. /**
  82. Define things that are only necessary in sub-projects, but not in the master-project itself
  83. */
  84. subprojects {
  85. //Put instructions for each sub project, but not the master
  86. apply plugin: 'java'
  87. apply plugin: 'jacoco'
  88. // See https://github.com/melix/japicmp-gradle-plugin
  89. apply plugin: 'me.champeau.gradle.japicmp'
  90. version = '5.0.1-SNAPSHOT'
  91. ext {
  92. bouncyCastleVersion = '1.67'
  93. commonsCodecVersion = '1.15'
  94. commonsCompressVersion = '1.20'
  95. commonsMathVersion = '3.6.1'
  96. japicmpversion = '5.0.0'
  97. junitVersion = '5.7.0'
  98. mockitoVersion = '3.6.0'
  99. hamcrestVersion = '2.2'
  100. slf4jVersion = '1.7.30'
  101. xmlbeansVersion = '4.0.0'
  102. }
  103. tasks.withType(JavaCompile) {
  104. options.encoding = 'UTF-8'
  105. }
  106. sourceCompatibility = 1.8
  107. targetCompatibility = 1.8
  108. repositories {
  109. mavenCentral()
  110. maven {
  111. url 'https://repository.apache.org/content/repositories/releases'
  112. }
  113. }
  114. dependencies {
  115. testCompile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  116. testCompile "org.mockito:mockito-core:${mockitoVersion}"
  117. testCompile "org.hamcrest:hamcrest:${hamcrestVersion}"
  118. }
  119. jar {
  120. manifest {
  121. attributes 'Implementation-Title': 'Apache POI', 'Implementation-Version': version
  122. }
  123. }
  124. test {
  125. // make XML test-results available for Jenkins CI
  126. useJUnitPlatform()
  127. reports {
  128. junitXml.enabled = true
  129. }
  130. // Exclude some tests that are not actually tests or do not run cleanly on purpose
  131. exclude '**/BaseTestBorderStyle.class'
  132. exclude '**/BaseTestCellUtil.class'
  133. exclude '**/TestUnfixedBugs.class'
  134. exclude '**/TestOneFile.class'
  135. // Exclude Test Suites
  136. exclude '**/All*Tests.class'
  137. exclude '**/HSSFTests.class'
  138. // set heap size for the test JVM(s)
  139. minHeapSize = "128m"
  140. maxHeapSize = "768m"
  141. // Specifying the local via system properties did not work, so we set them this way
  142. jvmArgs '-Duser.language=en -Duser.country=US'
  143. // show standard out and standard error of the test JVM(s) on the console
  144. //testLogging.showStandardStreams = true
  145. // http://forums.gradle.org/gradle/topics/jacoco_related_failure_in_multiproject_build
  146. systemProperties['user.dir'] = workingDir
  147. systemProperties['POI.testdata.path'] = '../../test-data'
  148. // this is necessary for JDK 9+ to keep formatting dates the same way as in previous JDK-versions
  149. systemProperties['java.locale.providers'] = 'JRE,CLDR'
  150. }
  151. jacoco {
  152. toolVersion = '0.8.6'
  153. }
  154. jacocoTestReport {
  155. reports {
  156. xml.enabled true
  157. }
  158. }
  159. // ensure the build-dir exists
  160. projectDir.mkdirs()
  161. if (project.hasProperty('enableSonar')) {
  162. // See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ and
  163. // https://docs.sonarqube.org/display/SONARQUBE52/Analyzing+with+SonarQube+Scanner+for+Gradle
  164. // for documentation of properties.
  165. //
  166. // Some additional properties are currently set in the Jenkins-DSL, see jenksin/create_jobs.groovy
  167. //
  168. sonarqube {
  169. properties {
  170. // as we currently use build/<module>/ as project-basedir, we need to tell Sonar to use
  171. // the root-folder as "basedir" for the projects
  172. property "sonar.projectBaseDir", "$projectDir/../.."
  173. // currently supported providers on Jenkins: "hg,git": property "sonar.scm.provider", "svn"
  174. // the plugin seems to not detect our non-standard build-layout
  175. property "sonar.junit.reportPaths", "$projectDir/build/test-results/test"
  176. property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
  177. }
  178. }
  179. }
  180. task(japicmp, type: me.champeau.gradle.ArtifactJapicmpTask, dependsOn: jar) {
  181. to = jar.archivePath
  182. onlyModified = true
  183. onlyBinaryIncompatibleModified = true
  184. failOnModification = false
  185. txtOutputFile = file("$buildDir/reports/japi.txt")
  186. htmlOutputFile = file("$buildDir/reports/japi.html")
  187. }
  188. }
  189. project('main') {
  190. sourceSets.main.java.srcDirs = ['../../src/java']
  191. sourceSets.main.resources.srcDirs = ['../../src/resources/main']
  192. sourceSets.test.java.srcDirs = ['../../src/testcases']
  193. dependencies {
  194. compile "commons-codec:commons-codec:${commonsCodecVersion}"
  195. compile 'commons-logging:commons-logging:1.2'
  196. compile 'org.apache.commons:commons-collections4:4.4'
  197. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  198. compile "org.slf4j:slf4j-api:${slf4jVersion}"
  199. compile 'javax.activation:activation:1.1.1'
  200. compile 'com.zaxxer:SparseBitSet:1.2'
  201. testCompile 'org.reflections:reflections:0.9.12'
  202. testRuntime "org.slf4j:slf4j-simple:${slf4jVersion}"
  203. }
  204. jar {
  205. manifest {
  206. attributes 'Automatic-Module-Name': 'org.apache.poi.main'
  207. }
  208. }
  209. // Create a separate jar for test-code to depend on it in other projects
  210. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  211. task testJar(type: Jar, dependsOn: testClasses) {
  212. baseName = "test-${project.archivesBaseName}"
  213. from sourceSets.test.output
  214. }
  215. configurations {
  216. tests
  217. }
  218. artifacts {
  219. tests testJar
  220. }
  221. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  222. }
  223. project('ooxml') {
  224. sourceSets.main.java.srcDirs = ['../../src/ooxml/java']
  225. sourceSets.main.resources.srcDirs = ['../../src/ooxml/resources', '../../src/resources/ooxml']
  226. sourceSets.test.java.srcDirs = ['../../src/ooxml/testcases']
  227. configurations {
  228. antdep
  229. }
  230. dependencies {
  231. antdep 'org.apache.ant:ant:1.10.9'
  232. }
  233. // we need to ensure that the custom ant tasks are compiled before we import the build.xml file
  234. ant.mkdir(dir: "../../build/poi-ant-contrib")
  235. ant.javac(srcdir: "../../src/excelant/poi-ant-contrib"
  236. , destdir: "../../build/poi-ant-contrib"
  237. , classpath: configurations.antdep.asPath
  238. , includeantruntime: "true"
  239. , excludes: "Junit5Progress.java"
  240. )
  241. // for now import the ant-task for building the jars from build.xml
  242. // we need to rename the tasks as e.g. task "jar" conflicts with :ooxml:jar
  243. ant.importBuild('../../build.xml') { antTargetName ->
  244. 'ant-' + antTargetName
  245. }
  246. compileJava.dependsOn 'ant-compile-ooxml-xsds'
  247. dependencies {
  248. compile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  249. compile 'org.apache.commons:commons-collections4:4.4'
  250. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  251. compile "org.apache.commons:commons-compress:${commonsCompressVersion}"
  252. compile 'org.apache.santuario:xmlsec:2.2.0'
  253. compile "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  254. compile 'com.github.virtuald:curvesapi:1.06'
  255. compile 'com.zaxxer:SparseBitSet:1.2'
  256. // compile only, don't add it to our dist as it blows up the size
  257. compile 'org.apache.xmlgraphics:batik-all:1.13'
  258. compile 'xml-apis:xml-apis-ext:1.3.04'
  259. compile 'org.apache.xmlgraphics:xmlgraphics-commons:2.4'
  260. compile 'org.apache.pdfbox:pdfbox:2.0.22'
  261. compile 'org.apache.pdfbox:fontbox:2.0.22'
  262. compile 'de.rototor.pdfbox:graphics2d:0.30'
  263. // for ooxml-lite, should we move this somewhere else?
  264. compile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  265. compile project(':main')
  266. compile project(':scratchpad') // TODO: get rid of this dependency!
  267. compile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  268. testCompile 'org.xmlunit:xmlunit-core:2.8.0'
  269. testCompile 'org.reflections:reflections:0.9.12'
  270. testCompile project(path: ':main', configuration: 'tests')
  271. testCompile 'org.openjdk.jmh:jmh-core:1.26'
  272. testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.26'
  273. testCompile 'com.google.guava:guava:30.0-jre'
  274. }
  275. jar {
  276. manifest {
  277. attributes 'Automatic-Module-Name': 'org.apache.poi.ooxml'
  278. }
  279. }
  280. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  281. test {
  282. // for some reason catching the OOM does not work when run from Gradle
  283. exclude '**/MemoryUsage.class'
  284. }
  285. }
  286. project('examples') {
  287. sourceSets.main.java.srcDirs = ['../../src/examples/src']
  288. dependencies {
  289. compile project(':main')
  290. compile project(':ooxml')
  291. compile project(':scratchpad')
  292. compile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  293. compile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  294. compile "org.apache.commons:commons-compress:${commonsCompressVersion}"
  295. }
  296. japicmp.enabled = false
  297. }
  298. project('excelant') {
  299. sourceSets.main.java.srcDirs = ['../../src/excelant/java']
  300. sourceSets.main.resources.srcDirs = ['../../src/excelant/resources']
  301. sourceSets.test.java.srcDirs = ['../../src/excelant/testcases']
  302. dependencies {
  303. compile 'org.apache.ant:ant:1.10.9'
  304. compile project(':main')
  305. compile project(':ooxml')
  306. testCompile project(path: ':main', configuration: 'tests')
  307. }
  308. jar {
  309. manifest {
  310. attributes 'Automatic-Module-Name': 'org.apache.poi.excelant'
  311. }
  312. }
  313. japicmp.baseline = "org.apache.poi:poi-excelant:${japicmpversion}@jar"
  314. }
  315. project('integrationtest') {
  316. sourceSets.test.java.srcDirs = ['../../src/integrationtest']
  317. dependencies {
  318. compile 'org.apache.ant:ant:1.10.9'
  319. compile project(':main')
  320. compile project(':ooxml')
  321. compile project(':scratchpad')
  322. compile project(':examples')
  323. testCompile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  324. testCompile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  325. testCompile files(this.project(':ooxml').sourceSets.test.runtimeClasspath)
  326. }
  327. jar {
  328. manifest {
  329. attributes 'Automatic-Module-Name': 'org.apache.poi.integrationtest'
  330. }
  331. }
  332. test {
  333. // exclude these from the normal test-run
  334. exclude '**/TestAllFiles.class'
  335. exclude '**/*FileHandler.class'
  336. exclude '**/RecordsStresser.class'
  337. }
  338. task integrationTest(type: Test) {
  339. // these are just tests used during development of more test-code
  340. exclude '**/*FileHandler.class'
  341. exclude '**/RecordStresser.class'
  342. }
  343. japicmp.enabled = false
  344. }
  345. project('scratchpad') {
  346. sourceSets.main.java.srcDirs = ['../../src/scratchpad/src']
  347. sourceSets.main.resources.srcDirs = ['../../src/resources/scratchpad']
  348. sourceSets.test.java.srcDirs = ['../../src/scratchpad/testcases']
  349. dependencies {
  350. compile project(':main')
  351. compile "commons-codec:commons-codec:${commonsCodecVersion}"
  352. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  353. // cyclic-dependency here: compile project(':ooxml')
  354. testCompile project(path: ':main', configuration: 'tests')
  355. }
  356. jar {
  357. manifest {
  358. attributes 'Automatic-Module-Name': 'org.apache.poi.scratchpad'
  359. }
  360. }
  361. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  362. }