From 06f91d0066d09b5ea7c91cc61b733cc7d90abc0b Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 15 Sep 2020 10:19:47 +0200 Subject: [PATCH] Refactor Gradle build This commit refactors the Gradle build with the following: * use of the dependency management plugin * import the Spring Boot BOM for dependency management * add support for publishing artifacts --- build.gradle | 88 +++++++-------- gradle/publishing.gradle | 104 ++++++++++++++++++ .../build.gradle | 10 +- .../build.gradle | 9 +- spring-graphql-common/build.gradle | 16 +-- spring-graphql-webflux/build.gradle | 19 +--- spring-graphql-webmvc/build.gradle | 20 +--- 7 files changed, 167 insertions(+), 99 deletions(-) create mode 100644 gradle/publishing.gradle diff --git a/build.gradle b/build.gradle index 49830ae91..c53524004 100644 --- a/build.gradle +++ b/build.gradle @@ -1,54 +1,40 @@ -import java.text.SimpleDateFormat - -subprojects { - - apply plugin: 'java' - apply plugin: 'maven' - - - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - version = "0.1" - group = 'org.springframework' - - ext { - graphqlJavaVersion = "15.0" - springVersion = "5.2.8.RELEASE" - springBootVersion = "2.3.2.RELEASE" - jacksonVersion = "2.9.8" - assertJVersion = "3.16.1" - } - - repositories { - mavenCentral() - mavenLocal() - } - - task sourcesJar(type: Jar) { - dependsOn classes - classifier 'sources' - from sourceSets.main.allSource - } - - task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir - } - - javadoc { - options.encoding = 'UTF-8' - } - test { - useJUnitPlatform() - testLogging { - events "passed", "skipped", "failed" - } - } - +plugins { + id 'org.springframework.boot' version '2.3.3.RELEASE' apply false } -task myWrapper(type: Wrapper) { - gradleVersion = '6.5.1' - distributionUrl = "https://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip" +subprojects { + apply plugin: 'java-library' + apply plugin: 'io.spring.dependency-management' + apply plugin: 'maven' + + group = 'org.springframework.experimental' + version = "0.1.0-SNAPSHOT" + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + + repositories { + mavenCentral() + } + + dependencyManagement { + imports { + mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES + } + dependencies { + dependency 'com.graphql-java:graphql-java:15.0' + } + } + + dependencies { + testImplementation 'org.springframework.boot:spring-boot-starter-test' + } + + test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + } + } + + apply from: "${rootDir}/gradle/publishing.gradle" } - diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle new file mode 100644 index 000000000..b23d6d61a --- /dev/null +++ b/gradle/publishing.gradle @@ -0,0 +1,104 @@ +apply plugin: "maven-publish" + +javadoc { + description = "Generates project-level javadoc for use in -javadoc jar" + + options.encoding = "UTF-8" + options.memberLevel = JavadocMemberLevel.PROTECTED + options.author = true + options.header = project.name + options.use = true + options.addStringOption("Xdoclint:none", "-quiet") + + // Suppress warnings due to cross-module @see and @link references. + // Note that global 'api' task does display all warnings. + logging.captureStandardError LogLevel.INFO + logging.captureStandardOutput LogLevel.INFO // suppress "## warnings" message +} + +task sourcesJar(type: Jar, dependsOn: classes) { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + archiveClassifier.set("sources") + from sourceSets.main.allSource +} + +task javadocJar(type: Jar) { + archiveClassifier.set("javadoc") + from javadoc +} + +publishing { + publications { + mavenJava(MavenPublication) { + pom { + afterEvaluate { + name = project.description + description = project.description + } + url = "https://github.com/spring-projects-experimental/spring-graphql" + organization { + name = "Spring IO" + url = "https://spring.io/projects" + } + licenses { + license { + name = "Apache License, Version 2.0" + url = "https://www.apache.org/licenses/LICENSE-2.0" + distribution = "repo" + } + } + scm { + url = "https://github.com/spring-projects-experimental/spring-graphql" + connection = "scm:git:git://github.com/spring-projects-experimental/spring-graphql" + developerConnection = "scm:git:git://github.com/spring-projects-experimental/spring-graphql" + } + developers { + developer { + id = "andimarek" + name = "Andi Marek" + email = "andimarek@fastmail.fm" + } + developer { + id = "rstoyanchev" + name = "Rossen Stoyanchev" + email = "rstoyanchev@vmware.com" + } + developer { + id = "bclozel" + name = "Brian Clozel" + email = "bclozel@vmware.com" + } + } + issueManagement { + system = "GitHub" + url = "https://github.com/spring-projects-experimental/spring-graphql/issues" + } + } + versionMapping { + usage('java-api') { + fromResolutionResult() + } + usage('java-runtime') { + fromResolutionResult() + } + } + from components.java + artifact sourcesJar + artifact javadocJar + } + } +} + +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-boot-starter-webflux/build.gradle b/spring-graphql-boot-starter-webflux/build.gradle index e2e693a51..4494fac16 100644 --- a/spring-graphql-boot-starter-webflux/build.gradle +++ b/spring-graphql-boot-starter-webflux/build.gradle @@ -1,9 +1,9 @@ -description = "GraphQL Java Spring Boot starter Webmvc" +description = "Starter for building GraphQL Java applications with Spring WebFlux" + dependencies { - implementation "org.springframework.boot:spring-boot-autoconfigure:$springBootVersion" implementation project(':spring-graphql-webflux') + implementation 'org.springframework.boot:spring-boot-autoconfigure' - testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" - testCompile "org.springframework.boot:spring-boot-starter-webflux:$springBootVersion" - + testCompile 'org.springframework.boot:spring-boot-starter-test' + testCompile 'org.springframework.boot:spring-boot-starter-webflux' } diff --git a/spring-graphql-boot-starter-webmvc/build.gradle b/spring-graphql-boot-starter-webmvc/build.gradle index da61604d1..02dd129c9 100644 --- a/spring-graphql-boot-starter-webmvc/build.gradle +++ b/spring-graphql-boot-starter-webmvc/build.gradle @@ -1,8 +1,9 @@ -description = "GraphQL Java Spring Boot starter Webmvc" +description = "Starter for building GraphQL Java applications with Spring WebFlux" + dependencies { - implementation "org.springframework.boot:spring-boot-autoconfigure:$springBootVersion" implementation project(':spring-graphql-webmvc') + implementation 'org.springframework.boot:spring-boot-autoconfigure' - testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" - testCompile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" + testCompile 'org.springframework.boot:spring-boot-starter-test' + testCompile 'org.springframework.boot:spring-boot-starter-web' } diff --git a/spring-graphql-common/build.gradle b/spring-graphql-common/build.gradle index ae7950d1d..3cf49eaf9 100644 --- a/spring-graphql-common/build.gradle +++ b/spring-graphql-common/build.gradle @@ -1,15 +1,7 @@ -description = "GraphQL Java Spring Common" - -apply plugin: 'java-library' +description = "Common module for GraphQL Java Spring support" dependencies { - implementation "org.springframework:spring-web:$springVersion" - api 'io.projectreactor:reactor-core:3.3.8.RELEASE' - api "com.graphql-java:graphql-java:$graphqlJavaVersion" - - testImplementation("org.assertj:assertj-core:$assertJVersion") - testImplementation('org.junit.jupiter:junit-jupiter:5.6.2') - testImplementation "org.springframework:spring-test:$springVersion" - testImplementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0' - testImplementation "org.mockito:mockito-core:2.+" + api 'io.projectreactor:reactor-core' + api "com.graphql-java:graphql-java" + implementation "org.springframework:spring-web" } diff --git a/spring-graphql-webflux/build.gradle b/spring-graphql-webflux/build.gradle index 007b675e3..17d7668d3 100644 --- a/spring-graphql-webflux/build.gradle +++ b/spring-graphql-webflux/build.gradle @@ -1,17 +1,10 @@ -description = "GraphQL Java Spring Webmvc integration" - -apply plugin: 'java-library' +description = "GraphQL Java Spring WebFlux integration" dependencies { - implementation "org.springframework:spring-webflux:$springVersion" - implementation "org.springframework:spring-context:$springVersion" - implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" - api "com.graphql-java:graphql-java:$graphqlJavaVersion" - implementation project(':spring-graphql-common') + api 'com.graphql-java:graphql-java' - testImplementation("org.assertj:assertj-core:$assertJVersion") - testImplementation('org.junit.jupiter:junit-jupiter:5.6.2') - testImplementation "org.springframework:spring-test:$springVersion" - testImplementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0' - testImplementation "org.mockito:mockito-core:2.+" + implementation project(':spring-graphql-common') + implementation 'org.springframework:spring-context' + implementation 'org.springframework:spring-webflux' + implementation 'com.fasterxml.jackson.core:jackson-databind' } diff --git a/spring-graphql-webmvc/build.gradle b/spring-graphql-webmvc/build.gradle index 9343a0b3a..1873a8231 100644 --- a/spring-graphql-webmvc/build.gradle +++ b/spring-graphql-webmvc/build.gradle @@ -1,18 +1,10 @@ -description = "GraphQL Java Spring Webmvc integration" - -apply plugin: 'java-library' +description = "GraphQL Java Spring MVC integration" dependencies { - implementation "org.springframework:spring-webmvc:$springVersion" - implementation "org.springframework:spring-context:$springVersion" - implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" - api "com.graphql-java:graphql-java:$graphqlJavaVersion" - implementation project(':spring-graphql-common') - implementation group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1' + api 'com.graphql-java:graphql-java' - testImplementation("org.assertj:assertj-core:$assertJVersion") - testImplementation('org.junit.jupiter:junit-jupiter:5.6.2') - testImplementation "org.springframework:spring-test:$springVersion" - testImplementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0' - testImplementation "org.mockito:mockito-core:2.+" + implementation project(':spring-graphql-common') + implementation 'org.springframework:spring-webmvc' + implementation 'com.fasterxml.jackson.core:jackson-databind' + implementation 'javax.servlet:javax.servlet-api' }