From 547d90490104faad80f9a3ae4c89b22d40d9e481 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Thu, 10 Feb 2022 08:03:59 +0000 Subject: [PATCH 1/2] Publish gradle-plugins to Maven Central --- .github/workflows/release-gradle-plugins.yml | 11 +++- .github/workflows/release.yml | 7 +- gradle-plugins/build.gradle.kts | 67 +++++++++++++++++++- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-gradle-plugins.yml b/.github/workflows/release-gradle-plugins.yml index 0a2b157c75fd..c87e7818f98f 100644 --- a/.github/workflows/release-gradle-plugins.yml +++ b/.github/workflows/release-gradle-plugins.yml @@ -158,8 +158,15 @@ jobs: # TODO (trask) cache gradle wrapper? - name: Build and publish gradle plugins + uses: gradle/gradle-build-action@v2 env: + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} + SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }} GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} - run: ../gradlew build publishPlugins - working-directory: gradle-plugins + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} + with: + # Don't use publishToSonatype since we don't want to publish the marker artifact + arguments: build publishPlugins publishPluginMavenPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository + build-root-directory: gradle-plugins diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc893f2f13ba..0d296cad32ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -157,10 +157,15 @@ jobs: - name: Build and publish gradle plugins uses: gradle/gradle-build-action@v2 env: + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} + SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }} GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} with: - arguments: build publishPlugins + # Don't use publishToSonatype since we don't want to publish the marker artifact + arguments: build publishPlugins publishPluginMavenPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository build-root-directory: gradle-plugins - name: Set release version diff --git a/gradle-plugins/build.gradle.kts b/gradle-plugins/build.gradle.kts index e216b427dcc6..3cdfcbb721e8 100644 --- a/gradle-plugins/build.gradle.kts +++ b/gradle-plugins/build.gradle.kts @@ -3,6 +3,7 @@ import java.time.Duration plugins { `kotlin-dsl` `maven-publish` + signing id("com.gradle.plugin-publish") id("io.github.gradle-nexus.publish-plugin") @@ -44,8 +45,16 @@ dependencies { testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") } -tasks.withType().configureEach { - useJUnitPlatform() +tasks { + withType().configureEach { + useJUnitPlatform() + } + + withType().configureEach { + with(options) { + release.set(8) + } + } } pluginBundle { @@ -67,6 +76,14 @@ gradlePlugin { } } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + } + withJavadocJar() + withSourcesJar() +} + nexusPublishing { packageGroup.set("io.opentelemetry") @@ -86,3 +103,49 @@ tasks { enabled = !version.toString().contains("SNAPSHOT") } } + +afterEvaluate { + publishing { + publications { + named("pluginMaven") { + pom { + name.set("OpenTelemetry Instrumentation Gradle Plugins") + description.set("Gradle plugins to assist developing OpenTelemetry instrumentation") + url.set("https://github.com/open-telemetry/opentelemetry-java-instrumentation") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + developers { + developer { + id.set("opentelemetry") + name.set("OpenTelemetry") + url.set("https://github.com/open-telemetry/opentelemetry-java-instrumentation/discussions") + } + } + + scm { + connection.set("scm:git:git@github.com:open-telemetry/opentelemetry-java-instrumentation.git") + developerConnection.set("scm:git:git@github.com:open-telemetry/opentelemetry-java-instrumentation.git") + url.set("git@github.com:open-telemetry/opentelemetry-java-instrumentation.git") + } + } + } + } + } + +// Sign only if we have a key to do so + val signingKey: String? = System.getenv("GPG_PRIVATE_KEY") +// Stub out entire signing block off of CI since Gradle provides no way of lazy configuration of +// signing tasks. + if (System.getenv("CI") != null && signingKey != null) { + signing { + useInMemoryPgpKeys(signingKey, System.getenv("GPG_PASSWORD")) + sign(publishing.publications["pluginMaven"]) + } + } +} From 79dd93a47201e482ddd2ceee31b13883e8d1c9ba Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Fri, 11 Feb 2022 10:31:42 +0900 Subject: [PATCH 2/2] Update .github/workflows/release-gradle-plugins.yml Co-authored-by: Trask Stalnaker --- .github/workflows/release-gradle-plugins.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release-gradle-plugins.yml b/.github/workflows/release-gradle-plugins.yml index c87e7818f98f..d6d60d76a37b 100644 --- a/.github/workflows/release-gradle-plugins.yml +++ b/.github/workflows/release-gradle-plugins.yml @@ -156,7 +156,6 @@ jobs: distribution: adopt java-version: 11 - # TODO (trask) cache gradle wrapper? - name: Build and publish gradle plugins uses: gradle/gradle-build-action@v2 env: