From b24f17b35cfc1fac058a36736154a21539969f3e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 9 Jul 2020 11:21:03 +0100 Subject: [PATCH] Rework spring-boot-docs to be a full-blown java project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, spring-boot-docs used the java-base-plugin and then added configuration on top. This has proven to be error prone, with the most recent problem being that the tests were not being compiled and run. This commit changes approach and applies the java plugin to the project instead of the java-base plugin. Now, rather than adding the necessary configuration to the base, the unwanted pieces of the java plugin's configuration – specifically the jar and javadoc tasks – are disabled instead. The DeployedPlugin has also been updated so that it does not create a publication from the java component for projects that have a disabled jar task. Closes gh-22284 --- .../boot/build/DeployedPlugin.java | 12 +++++++--- .../spring-boot-docs/build.gradle | 23 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/DeployedPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/DeployedPlugin.java index a05ebcb29a3..f0e18138771 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/DeployedPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/DeployedPlugin.java @@ -23,6 +23,7 @@ import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; +import org.gradle.api.tasks.bundling.Jar; /** * A plugin applied to a project that should be deployed. @@ -42,9 +43,14 @@ public class DeployedPlugin implements Plugin { project.getPlugins().apply(MavenRepositoryPlugin.class); PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); MavenPublication mavenPublication = publishing.getPublications().create("maven", MavenPublication.class); - project.getPlugins().withType(JavaPlugin.class) - .all((javaPlugin) -> project.getComponents().matching((component) -> component.getName().equals("java")) - .all((javaComponent) -> mavenPublication.from(javaComponent))); + project.afterEvaluate((evaluated) -> { + project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> { + if (((Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME)).isEnabled()) { + project.getComponents().matching((component) -> component.getName().equals("java")) + .all((javaComponent) -> mavenPublication.from(javaComponent)); + } + }); + }); project.getPlugins().withType(JavaPlatformPlugin.class) .all((javaPlugin) -> project.getComponents() .matching((component) -> component.getName().equals("javaPlatform")) diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 0e69688b101..c52cfaa211e 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -1,5 +1,5 @@ plugins { - id "java-base" + id "java" id "org.asciidoctor.jvm.convert" id "org.asciidoctor.jvm.pdf" id "org.springframework.boot.conventions" @@ -29,8 +29,12 @@ repositories { } } -sourceSets { - main +jar { + enabled = false +} + +javadoc { + enabled = false } plugins.withType(EclipsePlugin) { @@ -87,6 +91,15 @@ dependencies { mavenPluginDocumentation(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin", configuration: "documentation")) + testImplementation(project(":spring-boot-project:spring-boot-actuator-autoconfigure")) + testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) + testImplementation("org.assertj:assertj-core") + testImplementation("org.junit.jupiter:junit-jupiter") + + testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) + testRuntimeOnly("com.h2database:h2") + testRuntimeOnly("org.springframework:spring-jdbc") + testSlices(project(path: ":spring-boot-project:spring-boot-test-autoconfigure", configuration: "testSliceMetadata")) } @@ -94,7 +107,7 @@ task dependencyVersions(type: org.springframework.boot.build.constraints.Extract enforcedPlatform(":spring-boot-project:spring-boot-dependencies") } -task javadoc(type: Javadoc) { +task aggregatedJavadoc(type: Javadoc) { dependsOn dependencyVersions project.rootProject.gradle.projectsEvaluated { Set excludedProjects = ['spring-boot-antlib', 'spring-boot-configuration-metadata', 'spring-boot-configuration-processor', @@ -288,7 +301,7 @@ task zip(type: Zip) { from(asciidoctorMultipage.outputDir) { into "reference/html" } - from(javadoc) { + from(aggregatedJavadoc) { into "api" } into("gradle-plugin") {