docs.gradle 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. configurations {
  2. asciidoctorExt
  3. }
  4. dependencies {
  5. asciidoctorExt("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.4.0.RELEASE")
  6. }
  7. repositories {
  8. maven {
  9. url "https://repo.spring.io/release"
  10. mavenContent {
  11. includeGroup "io.spring.asciidoctor"
  12. }
  13. }
  14. }
  15. /**
  16. * Produce Javadoc for all Spring Framework modules in "build/docs/javadoc"
  17. */
  18. task api(type: Javadoc) {
  19. group = "Documentation"
  20. description = "Generates aggregated Javadoc API documentation."
  21. title = "${rootProject.description} ${version} API"
  22. dependsOn {
  23. moduleProjects.collect {
  24. it.tasks.getByName("jar")
  25. }
  26. }
  27. doFirst {
  28. classpath = files(
  29. // ensure the javadoc process can resolve types compiled from .aj sources
  30. project(":spring-aspects").sourceSets.main.output
  31. )
  32. classpath += files(moduleProjects.collect { it.sourceSets.main.compileClasspath })
  33. }
  34. options {
  35. encoding = "UTF-8"
  36. memberLevel = JavadocMemberLevel.PROTECTED
  37. author = true
  38. header = rootProject.description
  39. use = true
  40. overview = "src/docs/api/overview.html"
  41. stylesheetFile = file("src/docs/api/stylesheet.css")
  42. splitIndex = true
  43. links(project.ext.javadocLinks)
  44. addStringOption('Xdoclint:none', '-quiet')
  45. if(JavaVersion.current().isJava9Compatible()) {
  46. addBooleanOption('html5', true)
  47. }
  48. }
  49. source moduleProjects.collect { project ->
  50. project.sourceSets.main.allJava
  51. }
  52. maxMemory = "1024m"
  53. destinationDir = file("$buildDir/docs/javadoc")
  54. }
  55. /**
  56. * Produce KDoc for all Spring Framework modules in "build/docs/kdoc"
  57. */
  58. dokka {
  59. dependsOn {
  60. tasks.getByName("api")
  61. }
  62. doFirst {
  63. configuration {
  64. classpath = moduleProjects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
  65. classpath += files(moduleProjects.collect { it.sourceSets.main.compileClasspath })
  66. moduleProjects.findAll {
  67. it.pluginManager.hasPlugin("kotlin")
  68. }.each { project ->
  69. def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
  70. kotlinDirs -= project.sourceSets.main.java.srcDirs
  71. kotlinDirs.each { dir ->
  72. if (dir.exists()) {
  73. sourceRoot {
  74. path = dir.path
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. outputFormat = "html"
  82. outputDirectory = "$buildDir/docs/kdoc"
  83. configuration {
  84. moduleName = "spring-framework"
  85. externalDocumentationLink {
  86. url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
  87. packageListUrl = new File(buildDir, "docs/javadoc/package-list").toURI().toURL()
  88. }
  89. externalDocumentationLink {
  90. url = new URL("https://projectreactor.io/docs/core/release/api/")
  91. }
  92. externalDocumentationLink {
  93. url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
  94. }
  95. externalDocumentationLink {
  96. url = new URL("https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/")
  97. }
  98. }
  99. }
  100. task downloadResources(type: Download) {
  101. def version = "0.2.1.RELEASE"
  102. src "https://repo.spring.io/release/io/spring/docresources/" +
  103. "spring-doc-resources/$version/spring-doc-resources-${version}.zip"
  104. dest project.file("$buildDir/docs/spring-doc-resources.zip")
  105. onlyIfModified true
  106. useETag "all"
  107. }
  108. task extractDocResources(type: Copy, dependsOn: downloadResources) {
  109. from project.zipTree(downloadResources.dest);
  110. into "$buildDir/docs/spring-docs-resources/"
  111. }
  112. asciidoctorj {
  113. modules {
  114. pdf {
  115. version '1.5.0-beta.8'
  116. }
  117. }
  118. fatalWarnings ".*"
  119. options doctype: 'book', eruby: 'erubis'
  120. attributes([
  121. icons: 'font',
  122. idprefix: '',
  123. idseparator: '-',
  124. docinfo: 'shared',
  125. revnumber: project.version,
  126. sectanchors: '',
  127. sectnums: '',
  128. 'source-highlighter': 'highlight.js',
  129. highlightjsdir: 'js/highlight',
  130. 'highlightjs-theme': 'github', // 'googlecode',
  131. stylesdir: 'css/',
  132. stylesheet: 'stylesheet.css',
  133. 'spring-version': project.version
  134. ])
  135. }
  136. /**
  137. * Generate the Spring Framework Reference documentation from "src/docs/asciidoc"
  138. * in "build/docs/ref-docs/html5".
  139. */
  140. asciidoctor {
  141. baseDirFollowsSourceDir()
  142. configurations 'asciidoctorExt'
  143. sources {
  144. include '*.adoc'
  145. }
  146. outputDir "$buildDir/docs/ref-docs/html5"
  147. logDocuments = true
  148. resources {
  149. from(sourceDir) {
  150. include 'images/*', 'css/**', 'js/**'
  151. }
  152. from extractDocResources
  153. }
  154. }
  155. /**
  156. * Generate the Spring Framework Reference documentation from "src/docs/asciidoc"
  157. * in "build/docs/ref-docs/pdf".
  158. */
  159. asciidoctorPdf {
  160. baseDirFollowsSourceDir()
  161. configurations 'asciidoctorExt'
  162. sources {
  163. include '*.adoc'
  164. }
  165. outputDir "$buildDir/docs/ref-docs/pdf"
  166. logDocuments = true
  167. }
  168. /**
  169. * Zip all docs (API and reference) into a single archive
  170. */
  171. task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor', 'asciidoctorPdf', 'dokka']) {
  172. group = "Distribution"
  173. description = "Builds -${archiveClassifier} archive containing api and reference " +
  174. "for deployment at https://docs.spring.io/spring-framework/docs."
  175. archiveBaseName.set("spring-framework")
  176. archiveClassifier.set("docs")
  177. from("src/dist") {
  178. include "changelog.txt"
  179. }
  180. from (api) {
  181. into "javadoc-api"
  182. }
  183. from ("$asciidoctor.outputDir") {
  184. into "spring-framework-reference"
  185. }
  186. from ("$asciidoctorPdf.outputDir") {
  187. into "spring-framework-reference/pdf"
  188. }
  189. from (dokka) {
  190. into "kdoc-api"
  191. }
  192. }
  193. /**
  194. * Zip all Spring Framework schemas into a single archive
  195. */
  196. task schemaZip(type: Zip) {
  197. group = "Distribution"
  198. archiveBaseName.set("spring-framework")
  199. archiveClassifier.set("schema")
  200. description = "Builds -${archiveClassifier} archive containing all " +
  201. "XSDs for deployment at https://springframework.org/schema."
  202. duplicatesStrategy DuplicatesStrategy.EXCLUDE
  203. moduleProjects.each { module ->
  204. def Properties schemas = new Properties();
  205. module.sourceSets.main.resources.find {
  206. (it.path.endsWith("META-INF/spring.schemas") || it.path.endsWith("META-INF\\spring.schemas"))
  207. }?.withInputStream { schemas.load(it) }
  208. for (def key : schemas.keySet()) {
  209. def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
  210. assert shortName != key
  211. File xsdFile = module.sourceSets.main.resources.find {
  212. (it.path.endsWith(schemas.get(key)) || it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\')))
  213. }
  214. assert xsdFile != null
  215. into (shortName) {
  216. from xsdFile.path
  217. }
  218. }
  219. }
  220. }
  221. /**
  222. * Create a distribution zip with everything:
  223. * docs, schemas, jars, source jars, javadoc jars
  224. */
  225. task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
  226. group = "Distribution"
  227. archiveBaseName.set("spring-framework")
  228. archiveClassifier.set("dist")
  229. description = "Builds -${archiveClassifier} archive, containing all jars and docs, " +
  230. "suitable for community download page."
  231. ext.baseDir = "spring-framework-${project.version}";
  232. from("src/docs/dist") {
  233. include "readme.txt"
  234. include "license.txt"
  235. include "notice.txt"
  236. into "${baseDir}"
  237. expand(copyright: new Date().format("yyyy"), version: project.version)
  238. }
  239. from(zipTree(docsZip.archivePath)) {
  240. into "${baseDir}/docs"
  241. }
  242. from(zipTree(schemaZip.archivePath)) {
  243. into "${baseDir}/schema"
  244. }
  245. moduleProjects.each { module ->
  246. into ("${baseDir}/libs") {
  247. from module.jar
  248. if (module.tasks.findByPath("sourcesJar")) {
  249. from module.sourcesJar
  250. }
  251. if (module.tasks.findByPath("javadocJar")) {
  252. from module.javadocJar
  253. }
  254. }
  255. }
  256. }
  257. distZip.mustRunAfter moduleProjects.check