From dd3a30dd03ccd2ce02704f6f40ac3bb440cc21bf Mon Sep 17 00:00:00 2001 From: mworzala Date: Thu, 30 Nov 2023 23:38:27 +0200 Subject: [PATCH] chore: publish on maven central --- .github/workflows/release.yaml | 30 ++++++++++++ build.gradle.kts | 87 +++++++++++++++++++++++++++++++++- gradle/libs.versions.toml | 5 ++ 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..f5ffd01 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,30 @@ +name: Gradle Publish to Maven Central + +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + build: + runs-on: ubuntu-latest + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }} + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'temurin' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Publish to Sonatype + env: + TAG_VERSION: ${{ github.ref_name }} + run: | + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository + echo "Version: ${TAG_VERSION}" >> $GITHUB_STEP_SUMMARY diff --git a/build.gradle.kts b/build.gradle.kts index 33996af..706839d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,14 @@ plugins { `java-library` + + `maven-publish` + signing + alias(libs.plugins.nexuspublish) } -group = "net.hollowcube" -version = "1.0-SNAPSHOT" +group = "dev.hollowcube" +version = System.getenv("TAG_VERSION") ?: "dev" +description = "Schematic reader and writer for Minestom" repositories { mavenCentral() @@ -19,6 +24,84 @@ dependencies { testImplementation(libs.bundles.logback) } +java { + withSourcesJar() + withJavadocJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + tasks.test { useJUnitPlatform() +} + +nexusPublishing { + this.packageGroup.set("dev.hollowcube") + + repositories.sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + + if (System.getenv("SONATYPE_USERNAME") != null) { + username.set(System.getenv("SONATYPE_USERNAME")) + password.set(System.getenv("SONATYPE_PASSWORD")) + } + } +} + +publishing.publications.create("maven") { + groupId = "dev.hollowcube" + artifactId = "schem" + version = project.version.toString() + + from(project.components["java"]) + + pom { + name.set(artifactId) + description.set(project.description) + url.set("https://github.com/hollow-cube/schem") + + licenses { + license { + name.set("MIT") + url.set("https://github.com/hollow-cube/schem/blob/main/LICENSE") + } + } + + developers { + developer { + id.set("mworzala") + name.set("Matt Worzala") + email.set("matt@hollowcube.dev") + } + } + + issueManagement { + system.set("GitHub") + url.set("https://github.com/hollow-cube/schem/issues") + } + + scm { + connection.set("scm:git:git://github.com/hollow-cube/schem.git") + developerConnection.set("scm:git:git@github.com:hollow-cube/schem.git") + url.set("https://github.com/hollow-cube/schem") + tag.set(System.getenv("TAG_VERSION") ?: "HEAD") + } + + ciManagement { + system.set("Github Actions") + url.set("https://github.com/hollow-cube/schem/actions") + } + } +} + +signing { + isRequired = System.getenv("CI") != null + + val privateKey = System.getenv("GPG_PRIVATE_KEY") + val keyPassphrase = System.getenv()["GPG_PASSPHRASE"] + useInMemoryPgpKeys(privateKey, keyPassphrase) + + sign(publishing.publications) } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d6dc792..b7b7717 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,8 @@ metadata.format.version = "1.1" minestom = "8715f4305d" logback = "1.4.5" # For tests only +nexuspublish = "1.3.0" + [libraries] minestom = { group = "dev.hollowcube", name = "minestom-ce", version.ref = "minestom" } @@ -12,3 +14,6 @@ logback-classic = { group = "ch.qos.logback", name = "logback-classic", version. [bundles] logback = ["logback-core", "logback-classic"] + +[plugins] +nexuspublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexuspublish" }