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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0"
  21. }
  22. }
  23. plugins {
  24. id 'base'
  25. id("org.nosphere.apache.rat") version "0.7.0"
  26. }
  27. repositories {
  28. mavenCentral()
  29. }
  30. // Only add the plugin for Sonar if enabled
  31. if (project.hasProperty('enableSonar')) {
  32. println 'Enabling Sonar support'
  33. apply plugin: "org.sonarqube"
  34. }
  35. // For help converting an Ant build to a Gradle build, see
  36. // https://docs.gradle.org/current/userguide/ant.html
  37. configurations {
  38. antLibs {
  39. attributes {
  40. attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
  41. }
  42. }
  43. }
  44. dependencies {
  45. antLibs("org.junit.jupiter:junit-jupiter:5.7.1")
  46. antLibs("org.apache.ant:ant-junitlauncher:1.10.9")
  47. }
  48. ant.taskdef(name: "junit",
  49. classname: "org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.JUnitLauncherTask",
  50. classpath: configurations.antLibs.asPath)
  51. wrapper {
  52. // https://stackoverflow.com/a/54741656/2066598
  53. gradleVersion = '6.8'
  54. }
  55. task adjustWrapperPropertiesFile {
  56. doLast {
  57. ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) {
  58. fileset(dir: project.projectDir, includes: 'gradle/wrapper/gradle-wrapper.properties')
  59. }
  60. new File(project.projectDir, 'gradle/wrapper/gradle-wrapper.properties').with { it.text = it.readLines().findAll { it }.sort().join('\n') }
  61. ant.fixcrlf(file: 'gradle/wrapper/gradle-wrapper.properties', eol: 'lf')
  62. }
  63. }
  64. wrapper.finalizedBy adjustWrapperPropertiesFile
  65. /**
  66. Define properties for all projects, including this one
  67. */
  68. allprojects {
  69. apply plugin: 'eclipse'
  70. // apply plugin: 'idea'
  71. }
  72. /**
  73. Define things that are only necessary in sub-projects, but not in the master-project itself
  74. */
  75. subprojects {
  76. //Put instructions for each sub project, but not the master
  77. apply plugin: 'java-library'
  78. apply plugin: 'jacoco'
  79. apply plugin: 'maven-publish'
  80. version = '5.0.1-SNAPSHOT'
  81. ext {
  82. bouncyCastleVersion = '1.68'
  83. commonsCodecVersion = '1.15'
  84. commonsCompressVersion = '1.20'
  85. commonsMathVersion = '3.6.1'
  86. junitVersion = '5.7.1'
  87. log4jVersion = '2.14.0'
  88. mockitoVersion = '3.6.0'
  89. hamcrestVersion = '2.2'
  90. xmlbeansVersion = '5.0.0'
  91. batikVersion = '1.14'
  92. }
  93. tasks.withType(JavaCompile) {
  94. options.encoding = 'UTF-8'
  95. }
  96. tasks.withType(Jar) {
  97. duplicatesStrategy = 'fail'
  98. }
  99. sourceCompatibility = 1.8
  100. targetCompatibility = 1.8
  101. repositories {
  102. mavenCentral()
  103. maven {
  104. url 'https://repository.apache.org/content/repositories/releases'
  105. }
  106. }
  107. dependencies {
  108. testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
  109. testImplementation "org.mockito:mockito-core:${mockitoVersion}"
  110. testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
  111. testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
  112. }
  113. jar {
  114. manifest {
  115. attributes 'Implementation-Title': 'Apache POI', 'Implementation-Version': project.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. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'false'
  145. }
  146. jacoco {
  147. toolVersion = '0.8.6'
  148. }
  149. jacocoTestReport {
  150. reports {
  151. xml.enabled true
  152. }
  153. }
  154. // ensure the build-dir exists
  155. projectDir.mkdirs()
  156. if (project.hasProperty('enableSonar')) {
  157. // See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ and
  158. // https://docs.sonarqube.org/display/SONARQUBE52/Analyzing+with+SonarQube+Scanner+for+Gradle
  159. // for documentation of properties.
  160. //
  161. // Some additional properties are currently set in the Jenkins-DSL, see jenksin/create_jobs.groovy
  162. //
  163. sonarqube {
  164. properties {
  165. // as we currently use build/<module>/ as project-basedir, we need to tell Sonar to use
  166. // the root-folder as "basedir" for the projects
  167. property "sonar.projectBaseDir", "$projectDir"
  168. // currently supported providers on Jenkins: "hg,git": property "sonar.scm.provider", "svn"
  169. // the plugin seems to not detect our non-standard build-layout
  170. property "sonar.junit.reportPaths", "$projectDir/build/test-results/test"
  171. property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
  172. }
  173. }
  174. }
  175. task jenkins
  176. jenkins.dependsOn build
  177. jenkins.dependsOn check
  178. jenkins.dependsOn javadoc
  179. jenkins.dependsOn jacocoTestReport
  180. jenkins.dependsOn rat
  181. publishing {
  182. publications {
  183. POI(MavenPublication) {
  184. groupId 'org.apache.poi'
  185. pom {
  186. packaging = 'jar'
  187. url = 'https://poi.apache.org/'
  188. mailingLists {
  189. mailingList {
  190. name = 'POI Users List'
  191. subscribe = 'user-subscribe@poi.apache.org'
  192. unsubscribe = 'user-unsubscribe@poi.apache.org'
  193. archive = 'http://mail-archives.apache.org/mod_mbox/poi-user/'
  194. }
  195. mailingList {
  196. name = 'POI Developer List'
  197. subscribe = 'dev-subscribe@poi.apache.org'
  198. unsubscribe = 'dev-unsubscribe@poi.apache.org'
  199. archive = 'http://mail-archives.apache.org/mod_mbox/poi-dev/'
  200. }
  201. }
  202. licenses {
  203. license {
  204. name = 'Apache License, Version 2.0'
  205. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  206. distribution = 'repo'
  207. }
  208. }
  209. organization {
  210. name = 'Apache Software Foundation'
  211. url = 'http://www.apache.org/'
  212. }
  213. withXml {
  214. def r = asElement()
  215. def doc = r.getOwnerDocument()
  216. def asl = doc.createComment(new File('../legal/HEADER').text)
  217. // adding ASF header before root node is ignored
  218. // doc.insertBefore(asl, doc.getDocumentElement())
  219. r.insertBefore(asl, r.getFirstChild())
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. // Make JavaDoc behave similar to Ant, i.e. be a bit more lenient
  227. // and define amount of memory
  228. // https://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html
  229. if (JavaVersion.current().isJava8Compatible()) {
  230. allprojects {
  231. tasks.withType(Javadoc) {
  232. options.addStringOption('Xdoclint:none', '-quiet')
  233. maxMemory="384M"
  234. }
  235. }
  236. }
  237. // initial try to provide a combined JavaDoc, grouping is still missing here, though!
  238. task allJavaDoc(type: Javadoc) {
  239. source subprojects.collect { it.sourceSets.main.allJava }
  240. // for possible settings see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html
  241. classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
  242. destinationDir = file("${buildDir}/docs/javadoc")
  243. maxMemory="384M"
  244. // for possible options see https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
  245. options.use = true
  246. options.splitIndex = true
  247. title = 'POI API Documentation'
  248. options.bottom = '<![CDATA[<i>Copyright ' + new Date().format('yyyy') + ' The Apache Software Foundation or\n' +
  249. 'its licensors, as applicable.</i>]]>'
  250. options.group('DDF - Dreadful Drawing Format', 'org.apache.poi.ddf*')
  251. options.group('HPSF - Horrible Property Set Format', 'org.apache.poi.hpsf*')
  252. options.group('SS - Common Spreadsheet Format', 'org.apache.poi.ss*')
  253. options.group('HSSF - Horrible Spreadsheet Format', 'org.apache.poi.hssf*')
  254. options.group('XSSF - Open Office XML Spreadsheet Format', 'org.apache.poi.xssf*')
  255. options.group('SL - Common Slideshow Format', 'org.apache.poi.sl*')
  256. options.group('HSLF - Horrible Slideshow Format', 'org.apache.poi.hslf*', 'org.apache.poi.hwmf*', 'org.apache.poi.hemf*')
  257. options.group('XSLF - Open Office XML Slideshow Format', 'org.apache.poi.xslf*')
  258. options.group('HWPF - Horrible Word Processor Format', 'org.apache.poi.hwpf*')
  259. options.group('XWPF - Open Office XML Word Processor Format', 'org.apache.poi.xwpf*')
  260. options.group('HDGF - Horrible Diagram Format', 'org.apache.poi.hdgf*')
  261. options.group('XDGF - Open Office XML Diagram Format', 'org.apache.poi.xdgf*')
  262. options.group('HMEF - Transport Neutral Encoding Files (TNEF)', 'org.apache.poi.hmef*')
  263. options.group('HSMF Outlook message file format', 'org.apache.poi.hsmf*')
  264. options.group('HPBF - Publisher Format Files', 'org.apache.poi.hpbf*')
  265. options.group('POIFS - POI File System', 'org.apache.poi.poifs*')
  266. options.group('Utilities', 'org.apache.poi.util*')
  267. options.group('Excelant', 'org.apache.poi.ss.excelant**')
  268. options.group('Examples', 'org.apache.poi.examples*')
  269. }
  270. task jenkins
  271. jenkins.dependsOn allJavaDoc
  272. clean {
  273. delete "${rootDir}/build/dist"
  274. }
  275. rat {
  276. // Input directory, defaults to '.'
  277. inputDir.set(file("."))
  278. // include all directories which contain files that are included in releases
  279. includes.add("poi-examples/**")
  280. includes.add("poi-excelant/**")
  281. includes.add("poi-integration/**")
  282. includes.add("legal/**")
  283. includes.add("poi/**")
  284. includes.add("maven/**")
  285. includes.add("poi-ooxml/**")
  286. includes.add("poi-ooxml-full/**")
  287. includes.add("poi-ooxml-lite/**")
  288. includes.add("poi-ooxml-lite-agent/**")
  289. //includes.add("osgi/**")
  290. includes.add("poi-scratchpad/**")
  291. includes.add("src/**")
  292. //includes.add("sonar/**")
  293. includes.add("build.*")
  294. // List of Gradle exclude directives, defaults to ['**/.gradle/**']
  295. //excludes.add("main/java/org/apache/poi/**/*-chart-data.txt")
  296. includes.add("build.javacheck.xml")
  297. excludes.add("**/build/**")
  298. excludes.add("**/out/**")
  299. excludes.add("**/*.iml")
  300. excludes.add("**/*.log")
  301. excludes.add("**/main/java/org/apache/poi/**/*-chart-data.txt")
  302. excludes.add("poi/src/main/resources/org/apache/poi/sl/draw/geom/presetShapeDefinitions.xml")
  303. excludes.add("poi-ooxml/src/main/resources/org/apache/poi/xslf/usermodel/notesMaster.xml")
  304. excludes.add("poi-ooxml/src/main/resources/org/apache/poi/xssf/usermodel/presetTableStyles.xml")
  305. excludes.add("poi-ooxml-full/src/main/xmlschema/org/apache/poi/schemas/XAdES*.xsd")
  306. excludes.add("poi-ooxml-full/src/main/xmlschema/org/apache/poi/schemas/xmldsig-core-schema.xsd")
  307. excludes.add("poi-ooxml-full/src/main/xmlschema/org/apache/poi/xdgf/visio.xsd")
  308. /*
  309. <exclude name="documentation/*.txt" />
  310. <exclude name="documentation/content/xdocs/dtd/" />
  311. <exclude name="documentation/content/xdocs/entity/" />
  312. <exclude name="documentation/resources/images/pb-poi.cdr"/>
  313. */
  314. // Prints the list of files with unapproved licences to the console, defaults to false
  315. verbose.set(true)
  316. }
  317. /*task downloadJarsToLibs() {
  318. def f = new File("$projectDir/../lib/ooxml/xmlbeans-5.0.0.jar")
  319. if (!f.exists()) {
  320. println 'writing file ' + f.getAbsolutePath()
  321. f.getParentFile().mkdirs()
  322. new URL('https://ci-builds.apache.org/job/POI/job/POI-XMLBeans-DSL-1.8/lastSuccessfulBuild/artifact/build/xmlbeans-5.0.0.jar').withInputStream{ i -> f.withOutputStream{ it << i }}
  323. }
  324. }*/
  325. //compileJava.dependsOn 'downloadJarsToLibs'