From bceceff815293fc08feebaa3883893d98e85dc5c Mon Sep 17 00:00:00 2001 From: Philipp Schirmer Date: Thu, 29 Feb 2024 14:04:40 +0100 Subject: [PATCH] Setup Gradle plugins for correct snapshot publication (#47) --- .github/workflows/build-and-publish.yaml | 2 +- .github/workflows/release.yaml | 2 +- README.md | 20 ++++++++ build.gradle.kts | 59 +++++++++++------------- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml index a327d2c..3082cb3 100644 --- a/.github/workflows/build-and-publish.yaml +++ b/.github/workflows/build-and-publish.yaml @@ -8,7 +8,7 @@ on: jobs: build-and-publish: name: Java Gradle - uses: bakdata/ci-templates/.github/workflows/java-gradle-plugin.yaml@1.41.0 + uses: bakdata/ci-templates/.github/workflows/java-gradle-plugin.yaml@1.42.0 secrets: sonar-token: ${{ secrets.SONARCLOUD_TOKEN }} sonar-organization: ${{ secrets.SONARCLOUD_ORGANIZATION }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 86fe9aa..2e0e77a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,7 +16,7 @@ on: jobs: java-gradle-release: name: Java Gradle - uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.41.0 + uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.42.0 with: release-type: "${{ inputs.release-type }}" diff --git a/README.md b/README.md index d19caac..adff819 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,24 @@ A collection of small gradle plugin, mostly focused on deployment. **Sonar** Some defaults for easy integration of sonar on multi-module projects **Sonatype** is used for uploading to sonatype repos and ultimately publish to Maven Central +## Development +Snapshot versions of these plugins are published to Sonatype. +You can use them in your project by adding the following snippet to your `build.gradle.kts` + +``` +buildscript { + repositories { + maven { + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") + } + } + dependencies { + classpath("com.bakdata.gradle:sonar:0.0.1-SNAPSHOT") + classpath("com.bakdata.gradle:sonatype:0.0.1-SNAPSHOT") + } +} + +apply(plugin = "com.bakdata.sonar") +apply(plugin = "com.bakdata.sonatype") +``` diff --git a/build.gradle.kts b/build.gradle.kts index 42564b1..a3bd0d9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,42 +52,39 @@ subprojects { targetCompatibility = JavaVersion.VERSION_11 } - dependencies { - "testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.3.0") - "testImplementation"("org.junit.jupiter:junit-jupiter-api:5.3.0") - "testImplementation"("org.assertj", "assertj-core", "3.11.1") - "testImplementation"("org.junit-pioneer", "junit-pioneer", "0.3.0") + apply(plugin = "java-gradle-plugin") + + // config for gradle plugin portal doesn't support snapshot, so we add config only if release version + if (!version.toString().endsWith("-SNAPSHOT")) { + apply(plugin = "com.gradle.plugin-publish") } -} -// config for gradle plugin portal -// doesn't support snapshot, so we add config only if release version -if (!version.toString().endsWith("-SNAPSHOT")) { - subprojects.forEach { project -> - with(project) { - // com.gradle.plugin-publish depends on java-gradle-plugin, but it screws a bit this project - apply(plugin = "java-gradle-plugin") - apply(plugin = "com.gradle.plugin-publish") - project.afterEvaluate { - // java-gradle-plugin requires this block, but we already added the definitions in META-INF for unit testing... - configure { - plugins { - create("${project.name.capitalize()}Plugin") { - id = "com.bakdata.${project.name}" - implementationClass = "com.bakdata.gradle.${project.name.capitalize()}Plugin" - description = project.description - displayName = "Bakdata $name plugin" - } - } - } - // actual block of plugin portal config, need to be done on each subproject as the plugin does not support multi-module projects yet... - configure { - website = "https://github.com/bakdata/gradle-plugins" - vcsUrl = "https://github.com/bakdata/gradle-plugins" - tags = listOf("bakdata", name) + // description is only ready after evaluation + afterEvaluate { + configure { + plugins { + create("${project.name.capitalize()}Plugin") { + id = "com.bakdata.${project.name}" + implementationClass = "com.bakdata.gradle.${project.name.capitalize()}Plugin" + description = project.description + displayName = "Bakdata $name plugin" } } } + + extensions.findByType(com.gradle.publish.PluginBundleExtension::class)?.apply { + // actual block of plugin portal config, need to be done on each subproject as the plugin does not support multi-module projects yet... + website = "https://github.com/bakdata/gradle-plugins" + vcsUrl = "https://github.com/bakdata/gradle-plugins" + tags = listOf("bakdata", name) + } + } + + dependencies { + "testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.3.0") + "testImplementation"("org.junit.jupiter:junit-jupiter-api:5.3.0") + "testImplementation"("org.assertj", "assertj-core", "3.11.1") + "testImplementation"("org.junit-pioneer", "junit-pioneer", "0.3.0") } }