From e85017fded8a2403cce0751ee72aeddca9caacd4 Mon Sep 17 00:00:00 2001 From: Tofaa2 Date: Sat, 25 Oct 2025 17:37:40 +0400 Subject: [PATCH] Attempt at central publishing --- .github/workflows/dev-build-release.yml | 3 ++ .../workflows/publish-to-maven-central.yml | 37 +++++++++++++++++++ README.md | 19 +++++----- build.gradle.kts | 8 +++- .../entitylib.library-conventions.gradle.kts | 36 ++++++++++++------ 5 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/publish-to-maven-central.yml diff --git a/.github/workflows/dev-build-release.yml b/.github/workflows/dev-build-release.yml index e0ba3da..a921163 100644 --- a/.github/workflows/dev-build-release.yml +++ b/.github/workflows/dev-build-release.yml @@ -32,6 +32,9 @@ jobs: - name: Run build & publish with Gradle Wrapper if: github.ref == 'refs/heads/master' + env: + OSSRH_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.CENTRAL_PORTAL_TOKEN }} run: chmod +x ./gradlew && ./gradlew publishAllPublicationsToMavenRepository - name: Run build with Gradle Wrapper diff --git a/.github/workflows/publish-to-maven-central.yml b/.github/workflows/publish-to-maven-central.yml new file mode 100644 index 0000000..d01c372 --- /dev/null +++ b/.github/workflows/publish-to-maven-central.yml @@ -0,0 +1,37 @@ +name: Publish to Maven Central + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Install JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'temurin' + check-latest: true + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Import GPG key + run: | + echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --import --batch --yes + echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --pinentry-mode loopback --passphrase-fd 0 --batch --yes --import + + - name: Publish to Maven Central + env: + OSSRH_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.CENTRAL_PORTAL_TOKEN }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: ./gradlew publishAllPublicationsToMavenRepository --no-daemon \ No newline at end of file diff --git a/README.md b/README.md index 1336252..4e894ef 100644 --- a/README.md +++ b/README.md @@ -8,37 +8,36 @@ You can easily use EntityLib platformless by using the `api` or `common` module If you like EntityLib and or want to sponsor me, visit my [ko-fi page](https://ko-fi.com/tofaa) :D -EntityLib builds are available on [Jitpack](https://jitpack.io/#Tofaa2/EntityLib) and my own [Maven Repository](https://maven.evokegames.gg/#/snapshots/me/tofaa/entitylib) -The examples below use my repository, open the jitpack link for its group information. +EntityLib is published to [Maven Central](https://central.sonatype.com/artifact/io.github.tofaa2). Snapshots are available on pushes to the main branch, and stable releases are published on GitHub releases. Gradle (Groovy DSL): ```groovy repositories { - maven { url 'https://maven.evokegames.gg/snapshots' } + mavenCentral() } dependencies { - implementation 'me.tofaa.entitylib:::' } ``` Gradle (Kotlin DSL): ```kotlin repositories { - maven(url = "https://maven.evokegames.gg/snapshots") + mavenCentral() } dependencies { - implementation("me.tofaa.entitylib::") + implementation("io.github.tofaa2::") } ``` Maven: -```xml +```xml - me.tofaa.entitylib - (platform) - (latest-release-version) + io.github.tofaa2 + + ``` diff --git a/build.gradle.kts b/build.gradle.kts index 3e659db..b3ffe5e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import java.io.ByteArrayOutputStream val fullVersion = "3.0.3" val snapshot = true -group = "me.tofaa.entitylib" +group = "io.github.tofaa2" description = rootProject.name fun getVersionMeta(includeHash: Boolean): String { @@ -62,6 +62,12 @@ tasks { } } + register("publishAllPublicationsToMavenRepository") { + val publishTasks = subModuleTasks("publishAllPublicationsToMavenRepository") + dependsOn(publishTasks) + group = "publishing" + } + register("clean") { val cleanTasks = subModuleTasks("clean") dependsOn(cleanTasks) diff --git a/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts b/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts index 7c00174..3fcc198 100644 --- a/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts @@ -1,6 +1,7 @@ plugins { `java-library` `maven-publish` + signing } group = rootProject.group @@ -45,17 +46,6 @@ tasks { } publishing { - - repositories { - maven { - url = uri("https://maven.evokegames.gg/snapshots") - credentials { - username = System.getenv("TYCOONS_REPO_USER") - password = System.getenv("TYCOONS_REPO_PASS") - } - } - } - publications { create("EntityLib") { groupId = project.group as String @@ -75,6 +65,14 @@ publishing { } } + developers { + developer { + id = "Tofaa2" + name = "Tofaa" + email = "tofaadev@gmail.com" + } + } + scm { connection = "scm:git:https://github.com/Tofaa2/EntityLib.git" developerConnection = "scm:git:https://github.com/Tofaa2/EntityLib.git" @@ -83,6 +81,22 @@ publishing { } } } + + repositories { + maven { + url = uri("https://central.sonatype.com/api/v1/publisher/upload") + credentials { + username = System.getenv("CENTRAL_PORTAL_USERNAME") + password = System.getenv("CENTRAL_PORTAL_TOKEN") + } + } + } +} + +signing { + if (!version.toString().endsWith("-SNAPSHOT")) { + sign(publishing.publications["EntityLib"]) + } } // So that SNAPSHOT is always the latest SNAPSHOT