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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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.8'
  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. log4jVersion = '2.14.0'
  99. mockitoVersion = '3.6.0'
  100. hamcrestVersion = '2.2'
  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. testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
  119. }
  120. jar {
  121. manifest {
  122. attributes 'Implementation-Title': 'Apache POI', 'Implementation-Version': version
  123. }
  124. }
  125. test {
  126. // make XML test-results available for Jenkins CI
  127. useJUnitPlatform()
  128. reports {
  129. junitXml.enabled = true
  130. }
  131. // Exclude some tests that are not actually tests or do not run cleanly on purpose
  132. exclude '**/BaseTestBorderStyle.class'
  133. exclude '**/BaseTestCellUtil.class'
  134. exclude '**/TestUnfixedBugs.class'
  135. exclude '**/TestOneFile.class'
  136. // Exclude Test Suites
  137. exclude '**/All*Tests.class'
  138. exclude '**/HSSFTests.class'
  139. // set heap size for the test JVM(s)
  140. minHeapSize = "128m"
  141. maxHeapSize = "768m"
  142. // Specifying the local via system properties did not work, so we set them this way
  143. jvmArgs '-Duser.language=en -Duser.country=US'
  144. // show standard out and standard error of the test JVM(s) on the console
  145. //testLogging.showStandardStreams = true
  146. // http://forums.gradle.org/gradle/topics/jacoco_related_failure_in_multiproject_build
  147. systemProperties['user.dir'] = workingDir
  148. systemProperties['POI.testdata.path'] = '../../test-data'
  149. systemProperties['log4j.configurationFile'] = rootProject.file('log4j2-no-logging.xml')
  150. // this is necessary for JDK 9+ to keep formatting dates the same way as in previous JDK-versions
  151. systemProperties['java.locale.providers'] = 'JRE,CLDR'
  152. }
  153. jacoco {
  154. toolVersion = '0.8.6'
  155. }
  156. jacocoTestReport {
  157. reports {
  158. xml.enabled true
  159. }
  160. }
  161. // ensure the build-dir exists
  162. projectDir.mkdirs()
  163. if (project.hasProperty('enableSonar')) {
  164. // See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ and
  165. // https://docs.sonarqube.org/display/SONARQUBE52/Analyzing+with+SonarQube+Scanner+for+Gradle
  166. // for documentation of properties.
  167. //
  168. // Some additional properties are currently set in the Jenkins-DSL, see jenksin/create_jobs.groovy
  169. //
  170. sonarqube {
  171. properties {
  172. // as we currently use build/<module>/ as project-basedir, we need to tell Sonar to use
  173. // the root-folder as "basedir" for the projects
  174. property "sonar.projectBaseDir", "$projectDir/../.."
  175. // currently supported providers on Jenkins: "hg,git": property "sonar.scm.provider", "svn"
  176. // the plugin seems to not detect our non-standard build-layout
  177. property "sonar.junit.reportPaths", "$projectDir/build/test-results/test"
  178. property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
  179. }
  180. }
  181. }
  182. task(japicmp, type: me.champeau.gradle.ArtifactJapicmpTask, dependsOn: jar) {
  183. to = jar.archivePath
  184. onlyModified = true
  185. onlyBinaryIncompatibleModified = true
  186. failOnModification = false
  187. txtOutputFile = file("$buildDir/reports/japi.txt")
  188. htmlOutputFile = file("$buildDir/reports/japi.html")
  189. }
  190. }
  191. project('main') {
  192. sourceSets.main.java.srcDirs = ['../../src/java']
  193. sourceSets.main.resources.srcDirs = ['../../src/resources/main']
  194. sourceSets.test.java.srcDirs = ['../../src/testcases']
  195. dependencies {
  196. compile "commons-codec:commons-codec:${commonsCodecVersion}"
  197. compile 'org.apache.commons:commons-collections4:4.4'
  198. compile "org.apache.commons:commons-math3:${commonsMathVersion}"
  199. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  200. compile 'javax.activation:activation:1.1.1'
  201. compile 'com.zaxxer:SparseBitSet:1.2'
  202. testCompile 'org.reflections:reflections:0.9.12'
  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. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  257. // compile only, don't add it to our dist as it blows up the size
  258. compile 'org.apache.xmlgraphics:batik-all:1.13'
  259. compile 'xml-apis:xml-apis-ext:1.3.04'
  260. compile 'org.apache.xmlgraphics:xmlgraphics-commons:2.4'
  261. compile 'org.apache.pdfbox:pdfbox:2.0.22'
  262. compile 'org.apache.pdfbox:fontbox:2.0.22'
  263. compile 'de.rototor.pdfbox:graphics2d:0.30'
  264. // for ooxml-lite, should we move this somewhere else?
  265. compile "org.junit.jupiter:junit-jupiter:${junitVersion}"
  266. compile project(':main')
  267. compile project(':scratchpad') // TODO: get rid of this dependency!
  268. compile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  269. testCompile 'org.xmlunit:xmlunit-core:2.8.0'
  270. testCompile 'org.reflections:reflections:0.9.12'
  271. testCompile project(path: ':main', configuration: 'tests')
  272. testCompile 'org.openjdk.jmh:jmh-core:1.26'
  273. testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.26'
  274. testCompile 'com.google.guava:guava:30.0-jre'
  275. }
  276. jar {
  277. manifest {
  278. attributes 'Automatic-Module-Name': 'org.apache.poi.ooxml'
  279. }
  280. }
  281. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  282. test {
  283. // for some reason catching the OOM does not work when run from Gradle
  284. exclude '**/MemoryUsage.class'
  285. }
  286. }
  287. project('examples') {
  288. sourceSets.main.java.srcDirs = ['../../src/examples/src']
  289. dependencies {
  290. compile project(':main')
  291. compile project(':ooxml')
  292. compile project(':scratchpad')
  293. compile "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  294. implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
  295. compile files("../../build/dist/maven/poi-ooxml-full/poi-ooxml-full-${version}.jar")
  296. compile "org.apache.commons:commons-compress:${commonsCompressVersion}"
  297. }
  298. japicmp.enabled = false
  299. }
  300. project('excelant') {
  301. sourceSets.main.java.srcDirs = ['../../src/excelant/java']
  302. sourceSets.main.resources.srcDirs = ['../../src/excelant/resources']
  303. sourceSets.test.java.srcDirs = ['../../src/excelant/testcases']
  304. dependencies {
  305. compile 'org.apache.ant:ant:1.10.9'
  306. compile project(':main')
  307. compile project(':ooxml')
  308. testCompile project(path: ':main', configuration: 'tests')
  309. }
  310. jar {
  311. manifest {
  312. attributes 'Automatic-Module-Name': 'org.apache.poi.excelant'
  313. }
  314. }
  315. japicmp.baseline = "org.apache.poi:poi-excelant:${japicmpversion}@jar"
  316. }
  317. project('integrationtest') {
  318. sourceSets.test.java.srcDirs = ['../../src/integrationtest']
  319. dependencies {
  320. compile 'org.apache.ant:ant:1.10.9'
  321. compile project(':main')
  322. compile project(':ooxml')
  323. compile project(':scratchpad')
  324. compile project(':examples')
  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. implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
  356. // cyclic-dependency here: compile project(':ooxml')
  357. testCompile project(path: ':main', configuration: 'tests')
  358. }
  359. jar {
  360. manifest {
  361. attributes 'Automatic-Module-Name': 'org.apache.poi.scratchpad'
  362. }
  363. }
  364. japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
  365. }