From ca9a40d3870126189706ca86dcf4b13620337124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D0=B1=D0=BE=D0=BB=D0=B5=D0=B2=20=D0=92=D0=B0?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=D0=B8=D0=B9?= Date: Wed, 29 Jul 2026 11:17:15 +0300 Subject: [PATCH] Migrate to com.vanniktech.maven.publish plugin for Maven Central publishing - Replace manual publishing/signing configuration with com.vanniktech.maven.publish plugin - Remove maven-publish and signing plugins (handled by vanniktech plugin) - Remove withJavadocJar() (plugin handles this automatically) - Add mavenPublishing block with automatic publishing enabled - Simplify GitHub Actions workflow (single command instead of manual bundle creation) - Use ORG_GRADLE_PROJECT_* environment variables for secrets - Add inceptionYear = 2021 to POM metadata Benefits: - Less code (~50 lines removed) - Official recommended solution by Sonatype - Automatic validation and status monitoring - More reliable publishing process --- .github/workflows/main.yml | 38 ++++---------------- build.gradle | 74 +++++++++++++++----------------------- 2 files changed, 34 insertions(+), 78 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb8ac4a..c17246e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -179,36 +179,10 @@ jobs: - name: Set version from tag run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - - name: Publish to local repository + - name: Publish to Maven Central env: - SIGNING_KEY: ${{ secrets.SIGNING_KEY }} - SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} - run: ./gradlew publishPluginMavenPublicationToLocalRepoRepository - - - name: Create bundle - run: | - cd build/local-repo - find . -type f -name "*.asc" -o -name "*.jar" -o -name "*.pom" | sort - zip -r ../central-bundle.zip . - cd .. - ls -lh central-bundle.zip - - - name: Verify bundle structure - run: | - echo "Bundle contents:" - unzip -l build/central-bundle.zip - echo "" - echo "Bundle size:" - ls -lh build/central-bundle.zip - - - name: Upload to Central Portal - env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_TOKEN_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }} - run: | - curl --fail -v -X POST \ - -H "Authorization: Bearer $(echo -n ${SONATYPE_USERNAME}:${SONATYPE_PASSWORD} | base64)" \ - -F "file=@build/central-bundle.zip" \ - -F "name=mapstruct-plugin-${{ github.ref_name }}" \ - -F "publishingType=AUTOMATIC" \ - https://central.sonatype.com/api/v1/publisher/upload + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_TOKEN_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_TOKEN_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + run: ./gradlew publishToMavenCentral diff --git a/build.gradle b/build.gradle index 68f0cbd..db17a6c 100644 --- a/build.gradle +++ b/build.gradle @@ -2,9 +2,8 @@ plugins { id 'com.gradle.plugin-publish' version '2.1.1' id 'io.freefair.lombok' version '9.5.0' id 'org.sonarqube' version '7.3.1.8318' + id 'com.vanniktech.maven.publish' version '0.37.0' id 'java-gradle-plugin' - id 'maven-publish' - id 'signing' id 'jacoco' } @@ -72,7 +71,6 @@ java { sourceCompatibility = 17 targetCompatibility = 17 withSourcesJar() - withJavadocJar() } jacocoTestReport { @@ -93,55 +91,39 @@ sonarqube { } } -publishing { - publications { - pluginMaven(MavenPublication) { - pom { - name = 'MapStruct Plugin' - description = 'Automatic MapStruct configuration for Gradle' - url = 'https://github.com/AkaZver/mapstruct-plugin' - - licenses { - license { - name = 'The Apache License, Version 2.0' - url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - - developers { - developer { - id = 'akazver' - name = 'Vasiliy Sobolev' - email = 'aka.zver.007@gmail.com' - url = 'https://github.com/AkaZver' - } - } - - scm { - connection = 'scm:git:git://github.com/AkaZver/mapstruct-plugin.git' - developerConnection = 'scm:git:ssh://github.com/AkaZver/mapstruct-plugin.git' - url = 'https://github.com/AkaZver/mapstruct-plugin' - } +mavenPublishing { + publishToMavenCentral(true) + signAllPublications() + + pom { + name = 'MapStruct Plugin' + description = 'Automatic MapStruct configuration for Gradle' + inceptionYear = '2021' + url = 'https://github.com/AkaZver/mapstruct-plugin' + + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } - } - repositories { - maven { - name = 'localRepo' - url = layout.buildDirectory.dir('local-repo') + developers { + developer { + id = 'akazver' + name = 'Vasiliy Sobolev' + email = 'aka.zver.007@gmail.com' + url = 'https://github.com/AkaZver' + } } - } -} -signing { - def signingKey = System.getenv("SIGNING_KEY") - def signingPassword = System.getenv("SIGNING_PASSWORD") - required = signingKey != null && !version.toString().endsWith('SNAPSHOT') - if (signingKey != null) { - useInMemoryPgpKeys(signingKey, signingPassword) + scm { + url = 'https://github.com/AkaZver/mapstruct-plugin' + connection = 'scm:git:git://github.com/AkaZver/mapstruct-plugin.git' + developerConnection = 'scm:git:ssh://github.com/AkaZver/mapstruct-plugin.git' + } } - sign publishing.publications.pluginMaven } javadoc {