您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

build.gradle 20KB

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