Skip to content
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

Publish gradle-plugins to Maven Central #5333

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions .github/workflows/release-gradle-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,15 @@ jobs:

# TODO (trask) cache gradle wrapper?
anuraaga marked this conversation as resolved.
Show resolved Hide resolved
- 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does the publishPluginMavenPublicationToSonatypeRepository task come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nexus publish plugin

build-root-directory: gradle-plugins
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 65 additions & 2 deletions gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -44,8 +45,16 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
tasks {
withType<Test>().configureEach {
useJUnitPlatform()
}

withType<JavaCompile>().configureEach {
with(options) {
release.set(8)
}
}
}

pluginBundle {
Expand All @@ -67,6 +76,14 @@ gradlePlugin {
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
withJavadocJar()
withSourcesJar()
}

nexusPublishing {
packageGroup.set("io.opentelemetry")

Expand All @@ -86,3 +103,49 @@ tasks {
enabled = !version.toString().contains("SNAPSHOT")
}
}

afterEvaluate {
publishing {
publications {
named<MavenPublication>("pluginMaven") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does named imply that this task already exists?

Copy link
Contributor Author

@anuraaga anuraaga Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah Gradle plugin publish plugin creates it

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"])
}
}
}