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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. mavenCentral()
  19. }
  20. dependencies {
  21. classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1"
  22. classpath "de.thetaphi:forbiddenapis:3.1"
  23. }
  24. }
  25. plugins {
  26. id 'base'
  27. id("org.nosphere.apache.rat") version "0.7.0"
  28. }
  29. repositories {
  30. mavenCentral()
  31. }
  32. // Only add the plugin for Sonar if enabled
  33. if (project.hasProperty('enableSonar')) {
  34. println 'Enabling Sonar support'
  35. apply plugin: "org.sonarqube"
  36. }
  37. // For help converting an Ant build to a Gradle build, see
  38. // https://docs.gradle.org/current/userguide/ant.html
  39. configurations {
  40. antLibs {
  41. attributes {
  42. attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
  43. }
  44. }
  45. }
  46. dependencies {
  47. antLibs("org.junit.jupiter:junit-jupiter:5.7.1")
  48. antLibs("org.apache.ant:ant-junitlauncher:1.10.9")
  49. }
  50. ant.taskdef(name: "junit",
  51. classname: "org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.JUnitLauncherTask",
  52. classpath: configurations.antLibs.asPath)
  53. wrapper {
  54. // https://stackoverflow.com/a/54741656/2066598
  55. gradleVersion = '7.1'
  56. }
  57. task adjustWrapperPropertiesFile {
  58. doLast {
  59. ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) {
  60. fileset(dir: project.projectDir, includes: 'gradle/wrapper/gradle-wrapper.properties')
  61. }
  62. new File(project.projectDir, 'gradle/wrapper/gradle-wrapper.properties').with { it.text = it.readLines().findAll { it }.sort().join('\n') }
  63. ant.fixcrlf(file: 'gradle/wrapper/gradle-wrapper.properties', eol: 'lf')
  64. }
  65. }
  66. wrapper.finalizedBy adjustWrapperPropertiesFile
  67. /**
  68. Define properties for all projects, including this one
  69. */
  70. allprojects {
  71. // apply plugin: 'eclipse'
  72. apply plugin: 'idea'
  73. }
  74. /**
  75. Define things that are only necessary in sub-projects, but not in the master-project itself
  76. */
  77. subprojects {
  78. //Put instructions for each sub project, but not the master
  79. apply plugin: 'java-library'
  80. apply plugin: 'jacoco'
  81. apply plugin: 'maven-publish'
  82. apply plugin: 'signing'
  83. apply plugin: 'de.thetaphi.forbiddenapis'
  84. version = '5.0.1-SNAPSHOT'
  85. ext {
  86. bouncyCastleVersion = '1.69'
  87. commonsCodecVersion = '1.15'
  88. commonsCompressVersion = '1.20'
  89. commonsIoVersion = '2.10.0'
  90. commonsMathVersion = '3.6.1'
  91. junitVersion = '5.7.1'
  92. log4jVersion = '2.14.0'
  93. mockitoVersion = '3.6.0'
  94. hamcrestVersion = '2.2'
  95. xmlbeansVersion = '5.0.0'
  96. batikVersion = '1.14'
  97. JAVA9_SRC = 'src/main/java9'
  98. JAVA9_OUT = "${buildDir}/classes/java9/main/"
  99. TEST9_SRC = 'src/test/java9'
  100. TEST9_OUT = "${buildDir}/classes/java9/test/"
  101. VERSIONS9 = 'META-INF/versions/9'
  102. }
  103. tasks.withType(JavaCompile) {
  104. options.encoding = 'UTF-8'
  105. options.compilerArgs << '-Xlint:unchecked'
  106. options.deprecation = true
  107. }
  108. sourceCompatibility = JavaVersion.VERSION_1_8
  109. targetCompatibility = JavaVersion.VERSION_1_8
  110. repositories {
  111. mavenCentral()
  112. maven {
  113. url 'https://repository.apache.org/content/repositories/releases'
  114. }
  115. }
  116. dependencies {
  117. testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
  118. testImplementation "org.mockito:mockito-core:${mockitoVersion}"
  119. testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
  120. testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
  121. }
  122. task wrapper(type: Wrapper){
  123. // https://stackoverflow.com/a/65701523/2066598
  124. gradleVersion = '7.0.1'
  125. }
  126. java {
  127. withJavadocJar()
  128. withSourcesJar()
  129. }
  130. javadoc {
  131. failOnError = true
  132. maxMemory = "1024M"
  133. doFirst {
  134. options {
  135. if (JavaVersion.current().isJava9Compatible()) {
  136. addBooleanOption('html5', true)
  137. }
  138. addBooleanOption('Xdoclint:all,-missing', true)
  139. links 'https://poi.apache.org/apidocs/dev/'
  140. links 'https://docs.oracle.com/javase/8/docs/api/'
  141. links 'https://xmlbeans.apache.org/docs/5.0.0/'
  142. use = true
  143. splitIndex = true
  144. source = "1.8"
  145. }
  146. }
  147. }
  148. tasks.withType(Jar) {
  149. duplicatesStrategy = 'fail'
  150. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  151. doLast {
  152. ant.checksum(file: it.archivePath, algorithm: 'SHA-256', fileext: '.sha256', format: 'MD5SUM')
  153. ant.checksum(file: it.archivePath, algorithm: 'SHA-512', fileext: '.sha512', format: 'MD5SUM')
  154. }
  155. }
  156. jar {
  157. manifest {
  158. attributes 'Implementation-Title': 'Apache POI', 'Implementation-Version': project.version
  159. }
  160. }
  161. javadocJar {
  162. // if javadocs and binaries are in the same directory, JPMS complaints about duplicated modules
  163. // in the module-path
  164. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-javadoc")
  165. }
  166. sourcesJar {
  167. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  168. exclude 'META-INF/services/**'
  169. }
  170. test {
  171. // make XML test-results available for Jenkins CI
  172. useJUnitPlatform()
  173. reports {
  174. junitXml.enabled = true
  175. }
  176. // Exclude some tests that are not actually tests or do not run cleanly on purpose
  177. exclude '**/BaseTestBorderStyle.class'
  178. exclude '**/BaseTestCellUtil.class'
  179. exclude '**/TestUnfixedBugs.class'
  180. exclude '**/TestOneFile.class'
  181. include '**/TestSig*.class'
  182. // Exclude Test Suites
  183. exclude '**/All*Tests.class'
  184. exclude '**/HSSFTests.class'
  185. // set heap size for the test JVM(s)
  186. minHeapSize = "128m"
  187. maxHeapSize = "768m"
  188. // Specifying the local via system properties did not work, so we set them this way
  189. jvmArgs << [
  190. '-Djava.io.tmpdir=build',
  191. '-DPOI.testdata.path=../test-data',
  192. '-Djava.awt.headless=true',
  193. '-Djava.locale.providers=JRE,CLDR',
  194. '-Duser.language=en',
  195. '-Duser.country=US',
  196. '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
  197. "-Dversion.id=${project.version}",
  198. '-ea',
  199. '-Djunit.jupiter.execution.parallel.enabled=true',
  200. '-Djunit.jupiter.execution.parallel.config.strategy=fixed',
  201. '-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
  202. // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
  203. ]
  204. // show standard out and standard error of the test JVM(s) on the console
  205. //testLogging.showStandardStreams = true
  206. // http://forums.gradle.org/gradle/topics/jacoco_related_failure_in_multiproject_build
  207. systemProperties['user.dir'] = workingDir
  208. systemProperties['POI.testdata.path'] = '../test-data'
  209. // this is necessary for JDK 9+ to keep formatting dates the same way as in previous JDK-versions
  210. systemProperties['java.locale.providers'] = 'JRE,CLDR'
  211. systemProperties['junit.jupiter.execution.parallel.enabled'] = 'false'
  212. doFirst {
  213. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  214. jvmArgs += [
  215. '-Dsun.reflect.debugModuleAccessChecks=true',
  216. '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
  217. '--illegal-access=warn',
  218. // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
  219. // opposed to the recommendation there, it doesn't work to add ... to the dependencies
  220. // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
  221. // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
  222. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
  223. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
  224. ]
  225. }
  226. }
  227. }
  228. jacoco {
  229. toolVersion = '0.8.6'
  230. }
  231. jacocoTestReport {
  232. reports {
  233. xml.enabled true
  234. }
  235. }
  236. // ensure the build-dir exists
  237. projectDir.mkdirs()
  238. if (project.hasProperty('enableSonar')) {
  239. // See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ and
  240. // https://docs.sonarqube.org/display/SONARQUBE52/Analyzing+with+SonarQube+Scanner+for+Gradle
  241. // for documentation of properties.
  242. //
  243. // Some additional properties are currently set in the Jenkins-DSL, see jenksin/create_jobs.groovy
  244. //
  245. sonarqube {
  246. properties {
  247. // as we currently use build/<module>/ as project-basedir, we need to tell Sonar to use
  248. // the root-folder as "basedir" for the projects
  249. property "sonar.projectBaseDir", "$projectDir"
  250. // currently supported providers on Jenkins: "hg,git": property "sonar.scm.provider", "svn"
  251. // the plugin seems to not detect our non-standard build-layout
  252. property "sonar.junit.reportPaths", "$projectDir/build/test-results/test"
  253. // the Gradle run will report an invalid directory for 'ooxml-schema', but it seems to still work fine
  254. property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
  255. // somehow the version was not use properly
  256. property "sonar.projectVersion", version
  257. }
  258. }
  259. }
  260. forbiddenApis {
  261. bundledSignatures = [ 'jdk-unsafe', 'jdk-deprecated', 'jdk-internal', 'jdk-non-portable', 'jdk-reflection' ]
  262. signaturesFiles = files('../src/resources/devtools/forbidden-signatures.txt')
  263. ignoreFailures = false
  264. suppressAnnotations = [ 'org.apache.poi.util.SuppressForbidden' ]
  265. // forbiddenapis bundled signatures max supported version is 14
  266. targetCompatibility = (JavaVersion.VERSION_14.isCompatibleWith(JavaVersion.current()) ? JavaVersion.current() : JavaVersion.VERSION_14)
  267. }
  268. forbiddenApisMain {
  269. signaturesFiles = files('../src/resources/devtools/forbidden-signatures-prod.txt')
  270. }
  271. task jenkins
  272. jenkins.dependsOn build
  273. jenkins.dependsOn check
  274. jenkins.dependsOn javadoc
  275. jenkins.dependsOn jacocoTestReport
  276. jenkins.dependsOn rat
  277. publishing {
  278. publications {
  279. POI(MavenPublication) {
  280. groupId 'org.apache.poi'
  281. artifactId project.archivesBaseName
  282. from components.java
  283. pom {
  284. packaging = 'jar'
  285. url = 'https://poi.apache.org/'
  286. name = 'Apache POI'
  287. description = 'Apache POI - Java API To Access Microsoft Format Files'
  288. mailingLists {
  289. mailingList {
  290. name = 'POI Users List'
  291. subscribe = 'user-subscribe@poi.apache.org'
  292. unsubscribe = 'user-unsubscribe@poi.apache.org'
  293. archive = 'http://mail-archives.apache.org/mod_mbox/poi-user/'
  294. }
  295. mailingList {
  296. name = 'POI Developer List'
  297. subscribe = 'dev-subscribe@poi.apache.org'
  298. unsubscribe = 'dev-unsubscribe@poi.apache.org'
  299. archive = 'http://mail-archives.apache.org/mod_mbox/poi-dev/'
  300. }
  301. }
  302. licenses {
  303. license {
  304. name = 'Apache License, Version 2.0'
  305. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  306. distribution = 'repo'
  307. }
  308. }
  309. organization {
  310. name = 'Apache Software Foundation'
  311. url = 'http://www.apache.org/'
  312. }
  313. withXml {
  314. def r = asElement()
  315. def doc = r.getOwnerDocument()
  316. def hdr = new File('../legal/HEADER')
  317. if (!hdr.exists()) hdr = new File('legal/HEADER')
  318. def asl = doc.createComment(hdr.text)
  319. // adding ASF header before root node is ignored
  320. // doc.insertBefore(asl, doc.getDocumentElement())
  321. r.insertBefore(asl, r.getFirstChild())
  322. }
  323. }
  324. }
  325. }
  326. }
  327. generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"
  328. signing {
  329. sign publishing.publications.POI
  330. }
  331. }
  332. // initial try to provide a combined JavaDoc, grouping is still missing here, though!
  333. task allJavaDoc(type: Javadoc) {
  334. source subprojects.collect { it.sourceSets.main.allJava }
  335. // for possible settings see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html
  336. classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
  337. destinationDir = file("${buildDir}/docs/javadoc")
  338. maxMemory="768M"
  339. // for possible options see https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
  340. options.use = true
  341. options.splitIndex = true
  342. options.addBooleanOption('Xdoclint:all,-missing', true)
  343. title = 'POI API Documentation'
  344. options.bottom = '<![CDATA[<i>Copyright ' + new Date().format('yyyy') + ' The Apache Software Foundation or\n' +
  345. 'its licensors, as applicable.</i>]]>'
  346. options.group('DDF - Dreadful Drawing Format', 'org.apache.poi.ddf*')
  347. options.group('HPSF - Horrible Property Set Format', 'org.apache.poi.hpsf*')
  348. options.group('SS - Common Spreadsheet Format', 'org.apache.poi.ss*')
  349. options.group('HSSF - Horrible Spreadsheet Format', 'org.apache.poi.hssf*')
  350. options.group('XSSF - Open Office XML Spreadsheet Format', 'org.apache.poi.xssf*')
  351. options.group('SL - Common Slideshow Format', 'org.apache.poi.sl*')
  352. options.group('HSLF - Horrible Slideshow Format', 'org.apache.poi.hslf*', 'org.apache.poi.hwmf*', 'org.apache.poi.hemf*')
  353. options.group('XSLF - Open Office XML Slideshow Format', 'org.apache.poi.xslf*')
  354. options.group('HWPF - Horrible Word Processor Format', 'org.apache.poi.hwpf*')
  355. options.group('XWPF - Open Office XML Word Processor Format', 'org.apache.poi.xwpf*')
  356. options.group('HDGF - Horrible Diagram Format', 'org.apache.poi.hdgf*')
  357. options.group('XDGF - Open Office XML Diagram Format', 'org.apache.poi.xdgf*')
  358. options.group('HMEF - Transport Neutral Encoding Files (TNEF)', 'org.apache.poi.hmef*')
  359. options.group('HSMF Outlook message file format', 'org.apache.poi.hsmf*')
  360. options.group('HPBF - Publisher Format Files', 'org.apache.poi.hpbf*')
  361. options.group('POIFS - POI File System', 'org.apache.poi.poifs*')
  362. options.group('Utilities', 'org.apache.poi.util*')
  363. options.group('Excelant', 'org.apache.poi.ss.excelant**')
  364. options.group('Examples', 'org.apache.poi.examples*')
  365. }
  366. task jenkins
  367. jenkins.dependsOn allJavaDoc
  368. clean {
  369. delete "${rootDir}/build/dist"
  370. }
  371. rat {
  372. // Input directory, defaults to '.'
  373. inputDir.set(file("."))
  374. // include all directories which contain files that are included in releases
  375. includes.add("poi-examples/**")
  376. includes.add("poi-excelant/**")
  377. includes.add("poi-integration/**")
  378. includes.add("legal/**")
  379. includes.add("poi/**")
  380. includes.add("maven/**")
  381. includes.add("poi-ooxml/**")
  382. includes.add("poi-ooxml-full/**")
  383. includes.add("poi-ooxml-lite/**")
  384. includes.add("poi-ooxml-lite-agent/**")
  385. //includes.add("osgi/**")
  386. includes.add("poi-scratchpad/**")
  387. includes.add("src/**")
  388. //includes.add("sonar/**")
  389. includes.add("build.*")
  390. // List of Gradle exclude directives, defaults to ['**/.gradle/**']
  391. //excludes.add("main/java/org/apache/poi/**/*-chart-data.txt")
  392. excludes.add("build.javacheck.xml")
  393. excludes.add("**/build/**")
  394. excludes.add("**/out/**")
  395. excludes.add("**/*.iml")
  396. excludes.add("**/*.log")
  397. excludes.add("**/gradle-wrapper.properties")
  398. excludes.add("**/main/java/org/apache/poi/**/*-chart-data.txt")
  399. excludes.add("poi/src/main/resources/org/apache/poi/sl/draw/geom/presetShapeDefinitions.xml")
  400. excludes.add("poi-ooxml/src/main/resources/org/apache/poi/xslf/usermodel/notesMaster.xml")
  401. excludes.add("poi-ooxml/src/main/resources/org/apache/poi/xssf/usermodel/presetTableStyles.xml")
  402. excludes.add("poi-ooxml-full/src/main/xmlschema/org/apache/poi/schemas/XAdES*.xsd")
  403. excludes.add("poi-ooxml-full/src/main/xmlschema/org/apache/poi/schemas/xmldsig-core-schema.xsd")
  404. excludes.add("poi-ooxml-full/src/main/xmlschema/org/apache/poi/xdgf/visio.xsd")
  405. /*
  406. <exclude name="documentation/*.txt" />
  407. <exclude name="documentation/content/xdocs/dtd/" />
  408. <exclude name="documentation/content/xdocs/entity/" />
  409. <exclude name="documentation/resources/images/pb-poi.cdr"/>
  410. */
  411. // Prints the list of files with unapproved licences to the console, defaults to false
  412. verbose.set(true)
  413. }
  414. /*task downloadJarsToLibs() {
  415. def f = new File("$projectDir/../lib/ooxml/xmlbeans-5.0.0.jar")
  416. if (!f.exists()) {
  417. println 'writing file ' + f.getAbsolutePath()
  418. f.getParentFile().mkdirs()
  419. 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 }}
  420. }
  421. }*/
  422. //compileJava.dependsOn 'downloadJarsToLibs'
  423. task site(type:Exec) {
  424. doFirst {
  425. if (System.env.FORREST_HOME == null) {
  426. throw new InvalidUserDataException(
  427. 'Apache Forrest is not installed.\n' +
  428. 'Please install Apache Forrest (see https://forrest.apache.org/index.html) and set the\n' +
  429. 'FORREST_HOME environment variable!')
  430. }
  431. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  432. // maybe Java 9-11 works too?
  433. throw new GradleException("Apache Forrest must be executed with Java 8!")
  434. }
  435. }
  436. if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
  437. commandLine 'cmd', '/c', "${System.env.FORREST_HOME}/bin/forrest.bat"
  438. } else {
  439. commandLine "${System.env.FORREST_HOME}/bin/forrest"
  440. }
  441. //store the output instead of printing to the console:
  442. standardOutput = new ByteArrayOutputStream()
  443. ext.output = {
  444. return standardOutput.toString()
  445. }
  446. doLast {
  447. println 'Broken links:'
  448. println file("${buildDir}/tmp/brokenlinks.xml").text
  449. /* Apache Forrest is dead, so we cannot expect fixes there however it does not handle "https" in "credits"
  450. currently if the *.xml file is in a sub-directory, see Apache Forrest code at
  451. main/webapp/skins/pelt/xslt/html/site-to-xhtml.xsl:350
  452. So we need to replace the links afterwards to have a fully "https" website and avoid browser warning about
  453. a "mixed content" website */
  454. def buildSite = "${buildDir}/site"
  455. println "Fix https in ${buildSite}"
  456. ant.replace(dir: buildSite, summary:'true', includes:'**/*.html',
  457. token:'http://www.apache.org/events/current-event-125x125.png',
  458. value:'https://www.apache.org/events/current-event-125x125.png')
  459. ant.replace(dir: buildSite, summary:'true', includes:'**/*.html',
  460. token:'http://www.google.com/search',
  461. value:'https://www.google.com/search')
  462. ant.fixcrlf(srcdir: buildSite, includes:'**/*.html,**/*.css', eol:'unix', eof:'remove')
  463. }
  464. }