From 5b909ed662b7f123ab5334449762eeaa4145c6a0 Mon Sep 17 00:00:00 2001 From: Pavlo Shevchenko Date: Thu, 14 Mar 2024 10:09:41 +0100 Subject: [PATCH] Extract a convention plugin for configuring adapter projects --- buildSrc/build.gradle.kts | 7 +++++ .../adapters/SourceSetExtensions.kt | 8 +++++ .../develocity.adapters-library.gradle.kts | 27 +++++++++++++++++ .../build.gradle.kts | 29 ++++--------------- .../build.gradle.kts | 23 ++++----------- 5 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/develocity/adapters/SourceSetExtensions.kt create mode 100644 buildSrc/src/main/kotlin/develocity/adapters/develocity.adapters-library.gradle.kts diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..e4446d1 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +repositories { + gradlePluginPortal() +} + +plugins { + `kotlin-dsl` +} diff --git a/buildSrc/src/main/kotlin/develocity/adapters/SourceSetExtensions.kt b/buildSrc/src/main/kotlin/develocity/adapters/SourceSetExtensions.kt new file mode 100644 index 0000000..911ba6a --- /dev/null +++ b/buildSrc/src/main/kotlin/develocity/adapters/SourceSetExtensions.kt @@ -0,0 +1,8 @@ +package develocity.adapters + +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.tasks.SourceSetOutput +import org.gradle.kotlin.dsl.the + +fun Project.sourceSetOutput(name: String): SourceSetOutput = the().getByName(name).output diff --git a/buildSrc/src/main/kotlin/develocity/adapters/develocity.adapters-library.gradle.kts b/buildSrc/src/main/kotlin/develocity/adapters/develocity.adapters-library.gradle.kts new file mode 100644 index 0000000..833850a --- /dev/null +++ b/buildSrc/src/main/kotlin/develocity/adapters/develocity.adapters-library.gradle.kts @@ -0,0 +1,27 @@ +import develocity.adapters.sourceSetOutput + +plugins { + java +} + +repositories { + mavenCentral() +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } +} + +sourceSets { + create("compatibilityApi") + create("enterpriseCompatibility") + create("develocityCompatibility") +} + +tasks.jar { + from(sourceSetOutput("compatibilityApi")) + from(sourceSetOutput("enterpriseCompatibility")) + from(sourceSetOutput("develocityCompatibility")) +} diff --git a/develocity-gradle-plugin-adapters/build.gradle.kts b/develocity-gradle-plugin-adapters/build.gradle.kts index cc3177b..9ef94ba 100644 --- a/develocity-gradle-plugin-adapters/build.gradle.kts +++ b/develocity-gradle-plugin-adapters/build.gradle.kts @@ -1,5 +1,7 @@ +import develocity.adapters.sourceSetOutput + plugins { - java + id("develocity.adapters-library") } repositories { @@ -12,35 +14,14 @@ repositories { } } -sourceSets { - create("compatibilityApi") - create("enterpriseCompatibility") - create("develocityCompatibility") -} - -fun sourceSet(name: String): SourceSetOutput = sourceSets[name].output - dependencies { "compatibilityApiCompileOnly"(gradleApi()) "enterpriseCompatibilityCompileOnly"(gradleApi()) "enterpriseCompatibilityCompileOnly"(libs.gradle.enterprise.plugin) - "enterpriseCompatibilityImplementation"(sourceSet("compatibilityApi")) + "enterpriseCompatibilityImplementation"(sourceSetOutput("compatibilityApi")) "develocityCompatibilityCompileOnly"(gradleApi()) "develocityCompatibilityCompileOnly"(libs.develocity.plugin) - "develocityCompatibilityImplementation"(sourceSet("compatibilityApi")) -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } + "develocityCompatibilityImplementation"(sourceSetOutput("compatibilityApi")) } - -tasks.jar { - from(sourceSet("compatibilityApi")) - from(sourceSet("enterpriseCompatibility")) - from(sourceSet("develocityCompatibility")) -} - diff --git a/develocity-maven-plugin-adapters/build.gradle.kts b/develocity-maven-plugin-adapters/build.gradle.kts index 1ebd207..690acff 100644 --- a/develocity-maven-plugin-adapters/build.gradle.kts +++ b/develocity-maven-plugin-adapters/build.gradle.kts @@ -1,9 +1,10 @@ +import develocity.adapters.sourceSetOutput + plugins { - java + id("develocity.adapters-library") } repositories { - mavenCentral() maven { url = uri("https://repo.grdev.net/artifactory/public") content { @@ -12,28 +13,14 @@ repositories { } } -sourceSets { - create("compatibilityApi") - create("enterpriseCompatibility") - create("develocityCompatibility") -} - -fun sourceSet(name: String): SourceSetOutput = sourceSets[name].output - dependencies { "compatibilityApiCompileOnly"(libs.maven.core) "enterpriseCompatibilityCompileOnly"(libs.maven.core) "enterpriseCompatibilityCompileOnly"(libs.gradle.enterprise.extension) - "enterpriseCompatibilityImplementation"(sourceSet("compatibilityApi")) + "enterpriseCompatibilityImplementation"(sourceSetOutput("compatibilityApi")) "develocityCompatibilityCompileOnly"(libs.maven.core) "develocityCompatibilityCompileOnly"(libs.develocity.extension) - "develocityCompatibilityImplementation"(sourceSet("compatibilityApi")) -} - -tasks.jar { - from(sourceSet("compatibilityApi")) - from(sourceSet("enterpriseCompatibility")) - from(sourceSet("develocityCompatibility")) + "develocityCompatibilityImplementation"(sourceSetOutput("compatibilityApi")) }