diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 59820f3f..654a98ab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,17 +21,17 @@ jobs: with: fetch-depth: 0 - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v3 + uses: gradle/actions/wrapper-validation@v3 - name: Set up JDK 11 uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 check-latest: true + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 - name: Build - uses: gradle/gradle-build-action@v3 - with: - arguments: build --info + run: ./gradlew build --info - name: Publish unit test results (Ubuntu) uses: EnricoMi/publish-unit-test-result-action@v2 if: always() && matrix.os == 'ubuntu-latest' @@ -40,14 +40,14 @@ jobs: comment_mode: off check_name: "Test Results (Ubuntu)" - name: Publish unit test results (Windows) - uses: EnricoMi/publish-unit-test-result-action/composite@v2 + uses: EnricoMi/publish-unit-test-result-action/windows@v2 if: always() && matrix.os == 'windows-latest' with: files: "**/test-results/**/*.xml" comment_mode: off check_name: "Test Results (Windows)" - name: Publish unit test results (MacOS) - uses: EnricoMi/publish-unit-test-result-action/composite@v2 + uses: EnricoMi/publish-unit-test-result-action/macos@v2 if: always() && matrix.os == 'macos-latest' with: files: "**/test-results/**/*.xml" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 140919a2..b7780b8f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,27 +16,27 @@ jobs: with: fetch-depth: 0 - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v3 + uses: gradle/actions/wrapper-validation@v3 - name: Set up JDK 11 uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 check-latest: true + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 - name: Publish - uses: gradle/gradle-build-action@v3 - with: - arguments: | - publishMainPublicationToSonatypeRepository - closeAndReleaseSonatypeStagingRepository - publishPlugins - -Dorg.gradle.internal.http.socketTimeout=120000 - -Dorg.gradle.internal.network.retry.max.attempts=1 - -Dorg.gradle.internal.publish.checksums.insecure=true + run: | + ./gradlew + publishToMavenCentral + publishPlugins + --no-configuration-cache + -Dorg.gradle.internal.http.socketTimeout=120000 + -Dorg.gradle.internal.network.retry.max.attempts=1 env: - OSSRH_USERNAME: ${{ secrets.SONATYPE_USER }} - OSSRH_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - PGP_KEY: ${{ secrets.GPG_KEY_ARMORED }} - PGP_PASSWORD: ${{ secrets.GPG_PASSPHRASE }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_ARMORED }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} GRADLE_PORTAL_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} GRADLE_PORTAL_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/build.gradle.kts b/build.gradle.kts index a7fe086b..176c71d9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,6 @@ import com.gradle.publish.PublishTask.GRADLE_PUBLISH_KEY import com.gradle.publish.PublishTask.GRADLE_PUBLISH_SECRET +import com.vanniktech.maven.publish.SonatypeHost import org.jetbrains.kotlin.gradle.tasks.KotlinCompile repositories { @@ -12,11 +13,10 @@ plugins { alias(libs.plugins.pluginPublish) alias(libs.plugins.spotless) alias(libs.plugins.animalsniffer) - alias(libs.plugins.publishing) + alias(libs.plugins.mavenPublish) } group = "build.buf" -configurePublishing() allprojects { spotless { @@ -38,6 +38,14 @@ dependencies { testImplementation(libs.truth) } +object ProjectInfo { + const val NAME = "Buf Gradle Plugin" + const val URL = "https://github.com/bufbuild/buf-gradle-plugin" + const val DESCRIPTION = "Buf plugin for Gradle" +} + +fun isRelease() = !version.toString().endsWith("-SNAPSHOT") + gradlePlugin { website.set(ProjectInfo.URL) vcsUrl.set(ProjectInfo.URL) @@ -61,7 +69,42 @@ kotlin { } } +mavenPublishing { + publishToMavenCentral(SonatypeHost.S01) + signAllPublications() + pom { + name.set(ProjectInfo.NAME) + description.set(ProjectInfo.DESCRIPTION) + url.set(ProjectInfo.URL) + scm { + url.set(ProjectInfo.URL) + } + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("Andrew Parmet") + name.set("Andrew Parmet") + email.set("andrew@parmet.com") + } + developer { + id.set("bufbuild") + name.set("Buf") + email.set("dev@buf.build") + url.set("https://buf.build") + organization.set("Buf Technologies, Inc.") + organizationUrl.set("https://buf.build") + } + } + } +} + tasks { + // Only enable publishing to the Gradle Portal for release builds. named("publishPlugins") { enabled = isRelease() } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index a23bf66a..00000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - `kotlin-dsl` -} - -repositories { - gradlePluginPortal() -} - -dependencies { - implementation("io.github.gradle-nexus:publish-plugin:2.0.0") -} diff --git a/buildSrc/src/main/kotlin/ConfigurePublishing.kt b/buildSrc/src/main/kotlin/ConfigurePublishing.kt deleted file mode 100644 index d681d88a..00000000 --- a/buildSrc/src/main/kotlin/ConfigurePublishing.kt +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2023 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import io.github.gradlenexus.publishplugin.NexusPublishExtension -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.the -import org.gradle.kotlin.dsl.withType -import org.gradle.plugins.signing.SigningExtension - -private object Pgp { - val key by lazy { - System.getenv("PGP_KEY")?.replace('$', '\n') - } - - val password by lazy { - System.getenv("PGP_PASSWORD") - } -} - -private object Remote { - val username by lazy { - System.getenv("OSSRH_USERNAME") - } - - val password by lazy { - System.getenv("OSSRH_PASSWORD") - } -} - -object ProjectInfo { - const val NAME = "Buf Gradle Plugin" - const val URL = "https://github.com/bufbuild/buf-gradle-plugin" - const val DESCRIPTION = "Buf plugin for Gradle" -} - -fun Project.configurePublishing() { - apply(plugin = "io.github.gradle-nexus.publish-plugin") - - configure { - repositories { - sonatype { - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - username.set(Remote.username) - password.set(Remote.password) - } - } - packageGroup.set("build.buf") - } - - configure { - withSourcesJar() - } - - if (isRelease()) { - apply(plugin = "signing") - - configure { - useInMemoryPgpKeys(Pgp.key, Pgp.password) - the().publications.withType { - standardPom() - sign(this) - } - } - } - - configure { - publications { - create("main") { - from(components.getByName("java")) - artifactId = project.name - version = project.version.toString() - groupId = project.group.toString() - } - } - } -} - -private fun MavenPublication.standardPom() { - pom { - name.set(ProjectInfo.NAME) - description.set(ProjectInfo.DESCRIPTION) - url.set(ProjectInfo.URL) - scm { - url.set(ProjectInfo.URL) - } - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("Andrew Parmet") - name.set("Andrew Parmet") - email.set("andrew@parmet.com") - } - developer { - id.set("bufbuild") - name.set("Buf") - email.set("dev@buf.build") - url.set("https://buf.build") - organization.set("Buf Technologies, Inc.") - organizationUrl.set("https://buf.build") - } - } - } -} - -fun Project.isRelease() = !version.toString().endsWith("-SNAPSHOT") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 80daded2..ebd878a8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,8 +2,8 @@ # plugins animalsniffer = "1.7.1" kotlin = "1.9.24" +mavenPublish = "0.29.0" pluginPublish = "1.2.1" -publishing = "0.29.0" spotless = "6.25.0" # signature @@ -16,8 +16,8 @@ truth = "1.4.2" [plugins] animalsniffer = { id = "ru.vyarus.animalsniffer", version.ref = "animalsniffer" } kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +mavenPublish = { id = "com.vanniktech.maven.publish.base", version.ref = "mavenPublish" } pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish" } -publishing = { id = "com.vanniktech.maven.publish.base", version.ref = "publishing" } spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } [libraries]