From a1c5fcca58f7a7d7b77d10d392834167586141d1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 9 Jun 2021 12:51:55 +0100 Subject: [PATCH] Move common Asciidoctor configuration into our conventions Closes gh-26620 --- .../boot/build/AsciidoctorConventions.java | 28 +++++++++++++++++-- .../build.gradle | 6 ---- .../spring-boot-docs/build.gradle | 14 ---------- .../spring-boot-gradle-plugin/build.gradle | 13 --------- 4 files changed, 25 insertions(+), 36 deletions(-) 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 f82515d0e8..5afaa318a0 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java @@ -46,8 +46,15 @@ import org.springframework.util.StringUtils; * the plugin is applied: * * * * @@ -73,16 +81,20 @@ class AsciidoctorConventions { private static final String ASCIIDOCTORJ_VERSION = "2.4.1"; + private static final String EXTENSIONS_CONFIGURATION_NAME = "asciidoctorExtensions"; + void apply(Project project) { project.getPlugins().withType(AsciidoctorJPlugin.class, (asciidoctorPlugin) -> { - configureDocResourcesRepository(project); + configureDocumentationDependenciesRepository(project); makeAllWarningsFatal(project); upgradeAsciidoctorJVersion(project); + Configuration asciidoctorExtensions = createAsciidoctorExtensionsConfiguration(project); UnzipDocumentationResources unzipResources = createUnzipDocumentationResourcesTask(project); project.getTasks().withType(AbstractAsciidoctorTask.class, (asciidoctorTask) -> { configureCommonAttributes(project, asciidoctorTask); configureOptions(asciidoctorTask); asciidoctorTask.baseDirFollowsSourceDir(); + asciidoctorTask.configurations(asciidoctorExtensions); Sync syncSource = createSyncDocumentationSourceTask(project, asciidoctorTask); if (asciidoctorTask instanceof AsciidoctorTask) { configureHtmlOnlyAttributes(asciidoctorTask); @@ -104,10 +116,13 @@ class AsciidoctorConventions { }); } - private void configureDocResourcesRepository(Project project) { + private void configureDocumentationDependenciesRepository(Project project) { project.getRepositories().maven((mavenRepo) -> { mavenRepo.setUrl(URI.create("https://repo.spring.io/release")); - mavenRepo.mavenContent((mavenContent) -> mavenContent.includeGroup("io.spring.docresources")); + mavenRepo.mavenContent((mavenContent) -> { + mavenContent.includeGroup("io.spring.asciidoctor"); + mavenContent.includeGroup("io.spring.docresources"); + }); }); } @@ -119,6 +134,13 @@ class AsciidoctorConventions { project.getExtensions().getByType(AsciidoctorJExtension.class).setVersion(ASCIIDOCTORJ_VERSION); } + private Configuration createAsciidoctorExtensionsConfiguration(Project project) { + return project.getConfigurations().create(EXTENSIONS_CONFIGURATION_NAME, + (configuration) -> project.getConfigurations() + .matching((candidate) -> "dependencyManagement".equals(candidate.getName())) + .all((dependencyManagement) -> configuration.extendsFrom(dependencyManagement))); + } + private UnzipDocumentationResources createUnzipDocumentationResourcesTask(Project project) { Configuration documentationResources = project.getConfigurations().maybeCreate("documentationResources"); documentationResources.getDependencies() diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index fcfe443407..ea42f603eb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -11,9 +11,6 @@ plugins { description = "Spring Boot Actuator AutoConfigure" configurations { - asciidoctorExtensions { - extendsFrom dependencyManagement - } documentation } @@ -158,7 +155,6 @@ task dependencyVersions(type: org.springframework.boot.build.constraints.Extract tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) { dependsOn dependencyVersions - baseDirFollowsSourceDir() doFirst { def versionConstraints = dependencyVersions.versionConstraints def integrationVersion = versionConstraints["org.springframework.integration:spring-integration-core"] @@ -170,14 +166,12 @@ tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) { } asciidoctor { - configurations "asciidoctorExtensions" sources { include "index.adoc" } } asciidoctorPdf { - configurations "asciidoctorExtensions" 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 a5dd16d720..e26f515e4d 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -10,9 +10,6 @@ description = "Spring Boot Docs" configurations { actuatorApiDocumentation - asciidoctorExtensions { - extendsFrom dependencyManagement - } autoConfiguration configurationProperties gradlePluginDocumentation @@ -20,15 +17,6 @@ configurations { testSlices } -repositories { - maven { - url "https://repo.spring.io/release" - mavenContent { - includeGroup "io.spring.asciidoctor" - } - } -} - jar { enabled = false } @@ -187,8 +175,6 @@ task documentConfigurationProperties(type: org.springframework.boot.build.contex tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) { dependsOn dependencyVersions - configurations "asciidoctorExtensions" - baseDirFollowsSourceDir() asciidoctorj { fatalWarnings = ['^((?!successfully validated).)*$'] } 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 eaa866b8d2..f9bca24c68 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 @@ -15,21 +15,9 @@ toolchain { } configurations { - asciidoctorExtensions { - extendsFrom dependencyManagement - } documentation } -repositories { - maven { - url "https://repo.spring.io/release" - mavenContent { - includeGroup "io.spring.asciidoctor" - } - } -} - dependencies { asciidoctorExtensions("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch") @@ -85,7 +73,6 @@ tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) { } asciidoctor { - configurations "asciidoctorExtensions" sources { include "index.adoc" }