From 0458f15dddf5a407279f10ff2fad22829b0c3a93 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 6 Dec 2022 11:23:39 +0100 Subject: [PATCH] Move deployment repository config to a Gradle convention This commit moves the configuration of a local Maven deployment repository in a dedicated Gradle convention and applies it to all sub-projects. This separates the publishing configuration for actual project modules (that are meant to be published on Maven Central) from the infrastructure sub-projects such as the documentation one. --- build.gradle | 4 +- buildSrc/build.gradle | 4 ++ .../DeploymentConventionsPlugin.java | 45 +++++++++++++++++++ gradle/publishing.gradle | 15 ------- spring-graphql-docs/build.gradle | 11 ++--- 5 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 buildSrc/src/main/java/org/springframework/graphql/build/deployment/DeploymentConventionsPlugin.java diff --git a/build.gradle b/build.gradle index 7b7aa9b0..709983c3 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,9 @@ ext { description = "Spring for GraphQL" subprojects { + apply plugin: 'org.springframework.graphql.compiler' + apply plugin: 'org.springframework.graphql.deployment' + group = 'org.springframework.graphql' repositories { @@ -28,7 +31,6 @@ subprojects { configure(moduleProjects) { apply plugin: 'java-library' apply plugin: 'java-test-fixtures' - apply plugin: 'org.springframework.graphql.compiler' java { toolchain { diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 00cf7f16..d3439996 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -30,6 +30,10 @@ gradlePlugin { id = "org.springframework.graphql.compiler" implementationClass = "org.springframework.graphql.build.compile.CompilerConventionsPlugin" } + deploymentConventionsPlugin { + id = "org.springframework.graphql.deployment" + implementationClass = "org.springframework.graphql.build.deployment.DeploymentConventionsPlugin" + } } } diff --git a/buildSrc/src/main/java/org/springframework/graphql/build/deployment/DeploymentConventionsPlugin.java b/buildSrc/src/main/java/org/springframework/graphql/build/deployment/DeploymentConventionsPlugin.java new file mode 100644 index 00000000..0329893b --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/graphql/build/deployment/DeploymentConventionsPlugin.java @@ -0,0 +1,45 @@ +/* + * Copyright 2020-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.graphql.build.deployment; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.publish.PublishingExtension; +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; + +/** + * Convention that configures a local deployment Maven repository on the CI + * so that the Concourse resource can later push it to a remote repository. + * + * @author Brian Clozel + */ +public class DeploymentConventionsPlugin implements Plugin { + + @Override + public void apply(Project project) { + project.getPlugins().apply(MavenPublishPlugin.class); + project.getPlugins().withType(MavenPublishPlugin.class).forEach((mavenPublishPlugin) -> { + PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); + if (project.hasProperty("deploymentRepository")) { + publishing.getRepositories().maven((mavenArtifactRepository) -> { + mavenArtifactRepository.setUrl(project.property("deploymentRepository")); + mavenArtifactRepository.setName("deployment"); + }); + } + }); + } +} diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle index 295eec0e..45af077b 100644 --- a/gradle/publishing.gradle +++ b/gradle/publishing.gradle @@ -101,18 +101,3 @@ plugins.withType(JavaPlugin) { } } } - - -configureDeploymentRepository(project) - -void configureDeploymentRepository(Project project) { - project.plugins.withType(MavenPublishPlugin.class).all { - PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); - if (project.hasProperty("deploymentRepository")) { - publishing.repositories.maven { - it.url = project.property("deploymentRepository") - it.name = "deployment" - } - } - } -} diff --git a/spring-graphql-docs/build.gradle b/spring-graphql-docs/build.gradle index 90b9af78..bab75151 100644 --- a/spring-graphql-docs/build.gradle +++ b/spring-graphql-docs/build.gradle @@ -9,6 +9,10 @@ configurations { asciidoctorExtensions } +dependencies { + asciidoctorExtensions 'io.spring.asciidoctor.backends:spring-asciidoctor-backends:0.0.2' +} + jar { enabled = false } @@ -17,9 +21,6 @@ javadoc { enabled = false } -dependencies { - asciidoctorExtensions 'io.spring.asciidoctor.backends:spring-asciidoctor-backends:0.0.2' -} repositories { maven { @@ -91,6 +92,8 @@ asciidoctor { 'spring-boot-version': bootVersion } +asciidoctor.mustRunAfter "check" + /** * Zip all docs into a single archive */ @@ -106,8 +109,6 @@ task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor']) { } } -apply from: "${rootDir}/gradle/publishing.gradle" - publishing { publications { mavenJava(MavenPublication) {