Skip to content

build: migrate to use buildSrc and convention plugins #1633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 7 additions & 162 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Duration
import java.time.Instant

description = "Libraries for running a GraphQL server in Kotlin"
extra["isReleaseVersion"] = !version.toString().endsWith("SNAPSHOT")

@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
plugins {
kotlin("jvm")
id("org.jetbrains.dokka") apply false
id("org.jlleitschuh.gradle.ktlint")
id("io.gitlab.arturbosch.detekt")
jacoco
signing
`maven-publish`
id("io.github.gradle-nexus.publish-plugin")
alias(libs.plugins.nexus.publish)
}

allprojects {
buildscript {
repositories {
mavenCentral()
mavenLocal()
mavenLocal {
content {
includeGroup("com.expediagroup")
}
}
}
}

Expand All @@ -36,157 +31,7 @@ allprojects {
}
}

subprojects {
val kotlinJvmVersion: String by project

val currentProject = this

apply(plugin = "kotlin")
apply(plugin = "io.gitlab.arturbosch.detekt")
apply(plugin = "org.jlleitschuh.gradle.ktlint")
apply(plugin = "jacoco")
apply(plugin = "java-library")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "maven-publish")
apply(plugin = "signing")

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = kotlinJvmVersion
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}

check {
dependsOn(jacocoTestCoverageVerification)
}
detekt {
toolVersion = rootProject.project.libs.versions.detekt.get()
config = files("${rootProject.projectDir}/detekt.yml")
}
ktlint {
version.set(rootProject.project.libs.versions.ktlint.core.get())
}
jacoco {
toolVersion = rootProject.project.libs.versions.jacoco.get()
}
jar {
manifest {
attributes["Built-By"] = "Expedia Group"
attributes["Build-Jdk"] = "${System.getProperty("java.version")} (${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})"
attributes["Build-Timestamp"] = Instant.now().toString()
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
attributes["Implementation-Title"] = currentProject.name
attributes["Implementation-Version"] = project.version
}

// NOTE: in order to run gradle and maven plugin integration tests we need to have our build artifacts available in local repo
finalizedBy("publishToMavenLocal")
}
java {
// even though we don't have any Java code, since we are building using Java LTS version,
// this is required for Gradle to set the correct JVM versions in the module metadata
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}

// published sources and javadoc artifacts
val jarComponent = currentProject.components.getByName("java")
val sourcesJar by registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

val dokka = named("dokkaJavadoc", DokkaTask::class)
val javadocJar by registering(Jar::class) {
archiveClassifier.set("javadoc")
from("$buildDir/dokka/javadoc")
dependsOn(dokka)
}
publishing {
publications {
withType<MavenPublication> {
pom {
name.set("${currentProject.group}:${currentProject.name}")
url.set("https://github.com/ExpediaGroup/graphql-kotlin")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
organization {
name.set("Expedia Group")
name.set("https://www.expediagroup.com/")
}
developers {
developer {
name.set("Expedia Group Committers")
email.set("[email protected]")
organization.set("Expedia Group")
organizationUrl.set("https://www.expediagroup.com/")
}
}
scm {
connection.set("scm:git:git://github.com/ExpediaGroup/graphql-kotlin.git")
developerConnection.set("scm:git:git://github.com/ExpediaGroup/graphql-kotlin.git")
url.set("https://github.com/ExpediaGroup/graphql-kotlin")
}

// child projects need to be evaluated before their description can be read
val mavenPom = this
afterEvaluate {
mavenPom.description.set(currentProject.description)
}
}
}
// com.gradle.plugin-publish creates publication automatically
if (currentProject.name != "graphql-kotlin-gradle-plugin") {
create<MavenPublication>("mavenJava") {
from(jarComponent)
artifact(sourcesJar.get())
// no need to publish javadocs for SNAPSHOT builds
if (rootProject.extra["isReleaseVersion"] as Boolean) {
artifact(javadocJar.get())
}
}
}
}
}
signing {
setRequired {
(rootProject.extra["isReleaseVersion"] as Boolean) && (gradle.taskGraph.hasTask("publish") || gradle.taskGraph.hasTask("publishPlugins"))
}
val signingKey: String? = System.getenv("GPG_SECRET")
val signingPassword: String? = System.getenv("GPG_PASSPHRASE")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}

test {
useJUnitPlatform()
finalizedBy(jacocoTestReport)
}
}

// typesafe accessors to version catalog do not work in the subprojects/allprojects block, need to use rootProject.project
dependencies {
implementation(rootProject.project.libs.kotlin.stdlib)
implementation(rootProject.project.libs.kotlin.reflect)
implementation(rootProject.project.libs.kotlinx.coroutines.jdk8)
testImplementation(rootProject.project.libs.kotlin.test)
testImplementation(rootProject.project.libs.kotlin.junit.test)
testImplementation(rootProject.project.libs.junit.api)
testImplementation(rootProject.project.libs.junit.engine)
testImplementation(rootProject.project.libs.mockk)
}
}

tasks {
jar {
enabled = false
}
nexusPublishing {
repositories {
sonatype {
Expand Down
22 changes: 22 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
// Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
`kotlin-dsl`
}

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}

dependencies {
// add plugin artifacts so we can reference them in plugins block in the precompiled script
// in the future maybe we could update below to <plugin id>:<plugin id>.gradle.plugin:<plugin version> coordinates
implementation(libs.kotlin.gradle.plugin)
implementation(libs.detekt.plugin)
implementation(libs.dokka.plugin)
implementation(libs.ktlint.plugin)

// this is a workaround to enable version catalog usage in the convention plugin
// see https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Duration
import java.time.Instant

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("org.jlleitschuh.gradle.ktlint")
id("io.gitlab.arturbosch.detekt")
jacoco
`java-library`
signing
`maven-publish`
}

// this is a workaround to enable version catalog usage in the convention plugin
// see https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
val libs = the<LibrariesForLibs>()
tasks {
val kotlinJvmVersion: String by project
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = kotlinJvmVersion
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}

check {
dependsOn(jacocoTestCoverageVerification)
}
detekt {
toolVersion = libs.versions.detekt.get()
config = files("${rootProject.projectDir}/detekt.yml")
}
ktlint {
version.set(libs.versions.ktlint.core.get())
}
jacoco {
toolVersion = libs.versions.jacoco.get()
}
jar {
manifest {
attributes["Built-By"] = "Expedia Group"
attributes["Build-Jdk"] = "${System.getProperty("java.version")} (${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})"
attributes["Build-Timestamp"] = Instant.now().toString()
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
attributes["Implementation-Title"] = project.name
attributes["Implementation-Version"] = project.version
}

// NOTE: in order to run gradle and maven plugin integration tests we need to have our build artifacts available in local repo
finalizedBy("publishToMavenLocal")
}
java {
// even though we don't have any Java code, since we are building using Java LTS version,
// this is required for Gradle to set the correct JVM versions in the module metadata
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}

// published sources and javadoc artifacts
val jarComponent = project.components.getByName("java")
val sourcesJar by registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

val dokka = named("dokkaJavadoc", DokkaTask::class)
val javadocJar by registering(Jar::class) {
archiveClassifier.set("javadoc")
from("$buildDir/dokka/javadoc")
dependsOn(dokka)
}
publishing {
publications {
withType<MavenPublication> {
pom {
name.set("${project.group}:${project.name}")
url.set("https://github.com/ExpediaGroup/graphql-kotlin")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
organization {
name.set("Expedia Group")
name.set("https://www.expediagroup.com/")
}
developers {
developer {
name.set("Expedia Group Committers")
email.set("[email protected]")
organization.set("Expedia Group")
organizationUrl.set("https://www.expediagroup.com/")
}
}
scm {
connection.set("scm:git:git://github.com/ExpediaGroup/graphql-kotlin.git")
developerConnection.set("scm:git:git://github.com/ExpediaGroup/graphql-kotlin.git")
url.set("https://github.com/ExpediaGroup/graphql-kotlin")
}

// child projects need to be evaluated before their description can be read
val mavenPom = this
afterEvaluate {
mavenPom.description.set(project.description)
}
}
}
// com.gradle.plugin-publish creates publication automatically
if (project.name != "graphql-kotlin-gradle-plugin") {
create<MavenPublication>("mavenJava") {
from(jarComponent)
artifact(sourcesJar.get())
// no need to publish javadocs for SNAPSHOT builds
if (rootProject.extra["isReleaseVersion"] as Boolean) {
artifact(javadocJar.get())
}
}
}
}
}
signing {
setRequired {
(rootProject.extra["isReleaseVersion"] as Boolean) && (gradle.taskGraph.hasTask("publish") || gradle.taskGraph.hasTask("publishPlugins"))
}
val signingKey: String? = System.getenv("GPG_SECRET")
val signingPassword: String? = System.getenv("GPG_PASSPHRASE")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}

test {
useJUnitPlatform()
finalizedBy(jacocoTestReport)
}
}

dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlin.reflect)
implementation(libs.kotlinx.coroutines.jdk8)
testImplementation(libs.kotlin.test)
testImplementation(libs.kotlin.junit.test)
testImplementation(libs.junit.api)
testImplementation(libs.junit.engine)
testImplementation(libs.mockk)
}
4 changes: 4 additions & 0 deletions clients/graphql-kotlin-client-jackson/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
description = "GraphQL client serializer based on Jackson"

plugins {
id("com.expediagroup.graphql.conventions")
}

dependencies {
api(project(path = ":graphql-kotlin-client"))
api(libs.jackson)
Expand Down
4 changes: 3 additions & 1 deletion clients/graphql-kotlin-client-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
description = "GraphQL client serializer based on kotlinx.serialization"

@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
plugins {
kotlin("plugin.serialization")
id("com.expediagroup.graphql.conventions")
alias(libs.plugins.kotlin.serialization)
}

dependencies {
Expand Down
Loading