From 87d8aedd3c3944f029d24b7aaa77e310bf38856d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 10 May 2021 18:04:05 -0700 Subject: [PATCH] Use spring-pdf backend for PDF generation Update `asciidoctorPdf` tasks to use the `spring-pdf` backend so that chomped elements and @fold:on/@fold:off comments are hidden. Closes gh-26373 --- buildSrc/build.gradle | 3 +-- .../boot/build/AsciidoctorConventions.java | 10 +++++----- .../spring-boot-actuator-autoconfigure/build.gradle | 3 +-- spring-boot-project/spring-boot-docs/build.gradle | 3 +-- .../spring-boot-gradle-plugin/build.gradle | 3 +-- .../spring-boot-maven-plugin/build.gradle | 13 ++++++------- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index f7bfbae47a..19bd4d14c2 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -18,8 +18,7 @@ dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:2.11.4") implementation("commons-codec:commons-codec:1.13") implementation("org.apache.maven:maven-embedder:3.6.2") - implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.1.0") - implementation("org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.1.0") + implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.3.2") implementation("org.gradle:test-retry-gradle-plugin:1.1.9") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0-RC") implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.0-RC") diff --git a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java index e42df2919a..453b432c4e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java @@ -98,6 +98,8 @@ class AsciidoctorConventions { Configuration asciidoctorExtensions = configurations.maybeCreate(EXTENSIONS_CONFIGURATION); asciidoctorExtensions.getDependencies().add(project.getDependencies() .create("io.spring.asciidoctor.backends:spring-asciidoctor-backends:0.0.1-SNAPSHOT")); + asciidoctorExtensions.getDependencies() + .add(project.getDependencies().create("org.asciidoctor:asciidoctorj-pdf:1.5.3")); Configuration dependencyManagement = configurations.findByName("dependencyManagement"); if (dependencyManagement != null) { asciidoctorExtensions.extendsFrom(dependencyManagement); @@ -111,7 +113,9 @@ class AsciidoctorConventions { asciidoctorTask.baseDirFollowsSourceDir(); createSyncDocumentationSourceTask(project, asciidoctorTask); if (asciidoctorTask instanceof AsciidoctorTask) { - configureAsciidoctorHtmlTask((AsciidoctorTask) asciidoctorTask); + boolean pdf = asciidoctorTask.getName().toLowerCase().contains("pdf"); + String backend = (!pdf) ? "spring-html" : "spring-pdf"; + ((AsciidoctorTask) asciidoctorTask).outputOptions((outputOptions) -> outputOptions.backends(backend)); } } @@ -146,8 +150,4 @@ class AsciidoctorConventions { return syncDocumentationSource; } - private void configureAsciidoctorHtmlTask(AsciidoctorTask asciidoctorTask) { - asciidoctorTask.outputOptions((outputOptions) -> outputOptions.backends("spring-html")); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index a6b60c4bdd..2433cdd980 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -1,7 +1,6 @@ plugins { id "java-library" id "org.asciidoctor.jvm.convert" - id "org.asciidoctor.jvm.pdf" id "org.springframework.boot.auto-configuration" id "org.springframework.boot.conventions" id "org.springframework.boot.deployed" @@ -175,7 +174,7 @@ asciidoctor { } } -asciidoctorPdf { +task asciidoctorPdf(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { sources { include "index.adoc" } diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 65f29639b3..dc20d8abfe 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -2,7 +2,6 @@ plugins { id "java" id "groovy" id "org.asciidoctor.jvm.convert" - id "org.asciidoctor.jvm.pdf" id "org.springframework.boot.conventions" id "org.springframework.boot.deployed" } @@ -257,7 +256,7 @@ asciidoctor { } } -asciidoctorPdf { +task asciidoctorPdf(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { sources { include "*.singleadoc" } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle index e903028325..af9a5d2331 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle @@ -2,7 +2,6 @@ plugins { id "java-gradle-plugin" id "maven-publish" id "org.asciidoctor.jvm.convert" - id "org.asciidoctor.jvm.pdf" id "org.springframework.boot.conventions" id "org.springframework.boot.maven-repository" id "org.springframework.boot.optional-dependencies" @@ -82,7 +81,7 @@ asciidoctor { attributes "stylesheet": "css/style.css" } -asciidoctorPdf { +task asciidoctorPdf(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { sources { include "index.adoc" } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle index d1aa1e0a6c..1a74bb704a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle @@ -1,6 +1,5 @@ plugins { id "org.asciidoctor.jvm.convert" - id "org.asciidoctor.jvm.pdf" id "org.springframework.boot.conventions" id "org.springframework.boot.maven-plugin" id "org.springframework.boot.optional-dependencies" @@ -74,15 +73,15 @@ asciidoctor { } } -syncDocumentationSourceForAsciidoctorPdf { - from(documentPluginGoals) { - into "asciidoc/goals" +task asciidoctorPdf(type: org.asciidoctor.gradle.jvm.AsciidoctorTask) { + sources { + include "index.adoc" } } -asciidoctorPdf { - sources { - include "index.adoc" +syncDocumentationSourceForAsciidoctorPdf { + from(documentPluginGoals) { + into "asciidoc/goals" } }