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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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.0-SNAPSHOT'
  91. ext {
  92. bouncyCastleVersion = '1.67'
  93. commonsCodecVersion = '1.15'
  94. commonsCompressVersion = '1.20'
  95. commonsMathVersion = '3.6.1'
  96. japicmpversion = '4.1.2'
  97. junitVersion = '5.7.0'
  98. mockitoVersion = '3.6.0'
  99. slf4jVersion = '1.7.30'
  100. xmlbeansVersion = '4.0.0'
  101. }
  102. tasks.withType(JavaCompile) {
  103. options.encoding = 'UTF-8'
  104. }
  105. sourceCompatibility = 1.8
  106. targetCompatibility = 1.8
  107. repositories {
  108. mavenCentral()
  109. maven {
  110. url 'https://repository.apache.org/content/repositories/releases'
  111. }
  112. }
  113. jar {
  114. manifest {
  115. attributes 'Implementation-Title': 'Apache POI', 'Implementation-Version': version
  116. }
  117. }
  118. test {
  119. // make XML test-results available for Jenkins CI
  120. useJUnitPlatform()
  121. reports {
  122. junitXml.enabled = true
  123. }
  124. // Exclude some tests that are not actually tests or do not run cleanly on purpose
  125. exclude '**/BaseTestBorderStyle.class'
  126. exclude '**/BaseTestCellUtil.class'
  127. exclude '**/TestUnfixedBugs.class'
  128. exclude '**/TestOneFile.class'
  129. // Exclude Test Suites
  130. exclude '**/All*Tests.class'
  131. exclude '**/HSSFTests.class'
  132. // set heap size for the test JVM(s)
  133. minHeapSize = "128m"
  134. maxHeapSize = "768m"
  135. // Specifying the local via system properties did not work, so we set them this way
  136. jvmArgs '-Duser.language=en -Duser.country=US'
  137. // show standard out and standard error of the test JVM(s) on the console
  138. //testLogging.showStandardStreams = true
  139. // http://forums.gradle.org/gradle/topics/jacoco_related_failure_in_multiproject_build
  140. systemProperties['user.dir'] = workingDir
  141. systemProperties['POI.testdata.path'] = '../../test-data'
  142. // this is necessary for JDK 9+ to keep formatting dates the same way as in previous JDK-versions
  143. systemProperties['java.locale.providers'] = 'JRE,CLDR'
  144. }
  145. jacoco {
  146. toolVersion = '0.8.6'
  147. }
  148. jacocoTestReport {
  149. reports {
  150. xml.enabled true
  151. }
  152. }
  153. // ensure the build-dir exists
  154. projectDir.mkdirs()
  155. if (project.hasProperty('enableSonar')) {
  156. // See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ and
  157. // https://docs.sonarqube.org/display/SONARQUBE52/Analyzing+with+SonarQube+Scanner+for+Gradle
  158. // for documentation of properties.
  159. //
  160. // Some additional properties are currently set in the Jenkins-DSL, see jenksin/create_jobs.groovy
  161. //
  162. sonarqube {
  163. properties {
  164. // as we currently use build/<module>/ as project-basedir, we need to tell Sonar to use
  165. // the root-folder as "basedir" for the projects
  166. property "sonar.projectBaseDir", "$projectDir/../.."
  167. // currently supported providers on Jenkins: "hg,git": property "sonar.scm.provider", "svn"
  168. // the plugin seems to not detect our non-standard build-layout
  169. property "sonar.junit.reportPaths", "$projectDir/build/test-results/test"
  170. property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
  171. }
  172. }
  173. }
  174. task(japicmp, type: me.champeau.gradle.ArtifactJapicmpTask, dependsOn: jar) {
  175. to = jar.archivePath
  176. onlyModified = true
  177. onlyBinaryIncompatibleModified = true
  178. failOnModification = false
  179. txtOutputFile = file("$buildDir/reports/japi.txt")
  180. htmlOutputFile = file("$buildDir/reports/japi.html")
  181. }
  182. }
  183. project('main') {
  184. sourceSets.main.java.srcDirs = ['../../src/java']
  185. sourceSets.main.resources.srcDirs = ['../../src/resources/main']
  186. sourceSets.test.java.srcDirs = ['../../src/testcases']
  187. dependencies {
  188. compile "commons-codec:commons-codec:${commonsCodecVersion}"
  189. compile 'commons-logging:commons-logging:1.2'
  190. compile 'org.apache.commons:commons-collections4:4.4'
  191. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  192. compile "org.slf4j:slf4j-api:${slf4jVersion}"
  193. compile 'javax.activation:activation:1.1.1'
  194. compile 'com.zaxxer:SparseBitSet:1.2'
  195. testCompile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  196. testCompile "org.mockito:mockito-core:${mockitoVersion}"
  197. testCompile 'org.reflections:reflections:0.9.12'
  198. testRuntime "org.slf4j:slf4j-simple:${slf4jVersion}"
  199. testCompile 'org.hamcrest:hamcrest:2.2'
  200. }
  201. jar {
  202. manifest {
  203. attributes 'Automatic-Module-Name': 'org.apache.poi.main'
  204. }
  205. }
  206. // Create a separate jar for test-code to depend on it in other projects
  207. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  208. task testJar(type: Jar, dependsOn: testClasses) {
  209. baseName = "test-${project.archivesBaseName}"
  210. from sourceSets.test.output
  211. }
  212. configurations {
  213. tests
  214. }
  215. artifacts {
  216. tests testJar
  217. }
  218. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  219. }
  220. project('ooxml') {
  221. sourceSets.main.java.srcDirs = ['../../src/ooxml/java']
  222. sourceSets.main.resources.srcDirs = ['../../src/ooxml/resources', '../../src/resources/ooxml']
  223. sourceSets.test.java.srcDirs = ['../../src/ooxml/testcases']
  224. configurations {
  225. antdep
  226. }
  227. dependencies {
  228. antdep 'org.apache.ant:ant:1.10.9'
  229. }
  230. // we need to ensure that the custom ant tasks are compiled before we import the build.xml file
  231. ant.mkdir(dir: "../../build/poi-ant-contrib")
  232. ant.javac(srcdir: "../../src/excelant/poi-ant-contrib"
  233. , destdir: "../../build/poi-ant-contrib"
  234. , classpath: configurations.antdep.asPath
  235. , includeantruntime: "true"
  236. , excludes: "Junit5Progress.java"
  237. )
  238. // for now import the ant-task for building the jars from build.xml
  239. // we need to rename the tasks as e.g. task "jar" conflicts with :ooxml:jar
  240. ant.importBuild('../../build.xml') { antTargetName ->
  241. 'ant-' + antTargetName
  242. }
  243. compileJava.dependsOn 'ant-compile-ooxml-xsds'
  244. dependencies {
  245. compile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  246. compile 'org.apache.commons:commons-collections4:4.4'
  247. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  248. compile "org.apache.commons:commons-compress:${commonsCompressVersion}"
  249. compile 'org.apache.santuario:xmlsec:2.2.0'
  250. compile "org.bouncycastle:bcpkix-jdk15on:${bouncyCastleVersion}"
  251. compile 'com.github.virtuald:curvesapi:1.06'
  252. compile 'com.zaxxer:SparseBitSet:1.2'
  253. // compile only, don't add it to our dist as it blows up the size
  254. compile 'org.apache.xmlgraphics:batik-all:1.13'
  255. compile 'xml-apis:xml-apis-ext:1.3.04'
  256. compile 'org.apache.xmlgraphics:xmlgraphics-commons:2.4'
  257. compile 'org.apache.pdfbox:pdfbox:2.0.22'
  258. compile 'org.apache.pdfbox:fontbox:2.0.22'
  259. compile 'de.rototor.pdfbox:graphics2d:0.30'
  260. // for ooxml-lite, should we move this somewhere else?
  261. compile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  262. compile project(':main')
  263. compile project(':scratchpad') // TODO: get rid of this dependency!
  264. compile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  265. testCompile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  266. testCompile "org.mockito:mockito-core:${mockitoVersion}"
  267. testCompile 'org.xmlunit:xmlunit-core:2.8.0'
  268. testCompile 'org.reflections:reflections:0.9.12'
  269. testCompile project(path: ':main', configuration: 'tests')
  270. testCompile 'org.openjdk.jmh:jmh-core:1.26'
  271. testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.26'
  272. testCompile 'com.google.guava:guava:30.0-jre'
  273. }
  274. jar {
  275. manifest {
  276. attributes 'Automatic-Module-Name': 'org.apache.poi.ooxml'
  277. }
  278. }
  279. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  280. test {
  281. // for some reason catching the OOM does not work when run from Gradle
  282. exclude '**/MemoryUsage.class'
  283. }
  284. }
  285. project('examples') {
  286. sourceSets.main.java.srcDirs = ['../../src/examples/src']
  287. dependencies {
  288. compile project(':main')
  289. compile project(':ooxml')
  290. compile project(':scratchpad')
  291. compile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  292. compile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  293. compile "org.apache.commons:commons-compress:${commonsCompressVersion}"
  294. }
  295. japicmp.enabled = false
  296. }
  297. project('excelant') {
  298. sourceSets.main.java.srcDirs = ['../../src/excelant/java']
  299. sourceSets.main.resources.srcDirs = ['../../src/excelant/resources']
  300. sourceSets.test.java.srcDirs = ['../../src/excelant/testcases']
  301. dependencies {
  302. compile 'org.apache.ant:ant:1.10.9'
  303. compile project(':main')
  304. compile project(':ooxml')
  305. testCompile project(path: ':main', configuration: 'tests')
  306. testCompile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  307. testCompile 'org.hamcrest:hamcrest:2.2'
  308. }
  309. jar {
  310. manifest {
  311. attributes 'Automatic-Module-Name': 'org.apache.poi.excelant'
  312. }
  313. }
  314. japicmp.baseline = "org.apache.poi:poi-excelant:${japicmpversion}@jar"
  315. }
  316. project('integrationtest') {
  317. sourceSets.test.java.srcDirs = ['../../src/integrationtest']
  318. dependencies {
  319. compile 'org.apache.ant:ant:1.10.9'
  320. compile project(':main')
  321. compile project(':ooxml')
  322. compile project(':scratchpad')
  323. compile project(':examples')
  324. testCompile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  325. testCompile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  326. testCompile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  327. testCompile files(this.project(':ooxml').sourceSets.test.runtimeClasspath)
  328. }
  329. jar {
  330. manifest {
  331. attributes 'Automatic-Module-Name': 'org.apache.poi.integrationtest'
  332. }
  333. }
  334. test {
  335. // exclude these from the normal test-run
  336. exclude '**/TestAllFiles.class'
  337. exclude '**/*FileHandler.class'
  338. exclude '**/RecordsStresser.class'
  339. }
  340. task integrationTest(type: Test) {
  341. // these are just tests used during development of more test-code
  342. exclude '**/*FileHandler.class'
  343. exclude '**/RecordStresser.class'
  344. }
  345. japicmp.enabled = false
  346. }
  347. project('scratchpad') {
  348. sourceSets.main.java.srcDirs = ['../../src/scratchpad/src']
  349. sourceSets.main.resources.srcDirs = ['../../src/resources/scratchpad']
  350. sourceSets.test.java.srcDirs = ['../../src/scratchpad/testcases']
  351. dependencies {
  352. compile project(':main')
  353. compile "commons-codec:commons-codec:${commonsCodecVersion}"
  354. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  355. // cyclic-dependency here: compile project(':ooxml')
  356. testCompile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  357. testCompile "org.mockito:mockito-core:${mockitoVersion}"
  358. testCompile project(path: ':main', configuration: 'tests')
  359. }
  360. jar {
  361. manifest {
  362. attributes 'Automatic-Module-Name': 'org.apache.poi.scratchpad'
  363. }
  364. }
  365. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  366. }