From 8ef9bc8ee8ad055e589e8ded80052dff9bb6fa7e Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 16:38:11 +0100 Subject: [PATCH 01/10] Implement Git command execution for versioning Add functionality to retrieve Git metadata for versioning --- build.gradle.kts | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 1a28748..c74a604 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,6 +17,81 @@ plugins { id("org.jetbrains.kotlin.android") version "1.7.0" apply false } +// from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 +fun String.runCommand( + workingDir: File = File("."), + timeoutAmount: Long = 60, + timeoutUnit: TimeUnit = TimeUnit.SECONDS +): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) + .directory(workingDir) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.PIPE) + .start() + .apply { waitFor(timeoutAmount, timeoutUnit) } + .run { + val error = errorStream.bufferedReader().readText().trim() + if (error.isNotEmpty()) { + return@run "" + } + inputStream.bufferedReader().readText().trim() + } + +val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) +val tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) +val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) + +val finalVersion = System.getenv("version") ?: tag.drop(1) ?: "1.0.0" +val finalGroup = System.getenv("group") ?: "com.dzeio" +val artifact = System.getenv("artifact") ?: "crashhandler" + +group = finalGroup +version = finalVersion + +publishing { + publications { + create("maven") { + groupId = finalGroup + artifactId = artifact + version = finalVersion + + from(components["java"]) + + pom { + name.set("TCGdex SDK") + description.set("Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK") + url.set("https://github.com/dzeiocom/crashhandler") + licenses { + license { + name.set("MIT License") + url.set("https://github.com/dzeiocom/crashhandler/blob/master/LICENSE") + } + } + developers { + developer { + id.set("avior") + name.set("Avior") + email.set("contact@dze.io") + } + } + scm { + connection.set("scm:git@github.com:dzeiocom/crashhandler.git") + url.set("https://github.com/dzeiocom/crashhandler") + } + } + } + } + repositories { + maven { + name = "GithubPackages" + url = uri("https://maven.pkg.github.com/dzeiocom/crashhandler") + credentials { + username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") + password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") + } + } + } +} + task("clean") { delete(rootProject.buildDir) delete(project.buildDir) From 8f76e8a6ae35215931e4a030e7d949d06e88f186 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 16:40:33 +0100 Subject: [PATCH 02/10] Update build.yml --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 068c5a5..613d7a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,9 +26,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' From ff2f60294e6b5980fced449d6e485a8543e821d8 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 16:42:46 +0100 Subject: [PATCH 03/10] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 613d7a6..57f3e69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: - name: Zip artifacts run: zip -r assemble.zip . -i '**/build/*.apk' '**/build/*.aab' '**/build/*.aar' '**/build/*.so' - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v7 with: name: assemble path: assemble.zip From d77166e81d31ffb19c93332e762a4f75319a8093 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 16:46:19 +0100 Subject: [PATCH 04/10] Update build.gradle.kts --- build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index c74a604..8eba99b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,10 @@ plugins { id("com.android.application") version "8.1.1" apply false id("com.android.library") version "8.1.1" apply false id("org.jetbrains.kotlin.android") version "1.7.0" apply false + + // Apply the java-library plugin for API and implementation separation. + `java-library` + `maven-publish` } // from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 From 8041ef185759e5f06ceb0b4c64ebea758eb3ad71 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 17:01:15 +0100 Subject: [PATCH 05/10] d --- build.gradle.kts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8eba99b..70a5ebc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,8 +61,8 @@ publishing { from(components["java"]) pom { - name.set("TCGdex SDK") - description.set("Communicate with the Open Source TCGdex API in Kotlin/Java using the SDK") + name.set("Crash Handler") + description.set("Library that help handling crashes") url.set("https://github.com/dzeiocom/crashhandler") licenses { license { @@ -96,7 +96,7 @@ publishing { } } -task("clean") { - delete(rootProject.buildDir) - delete(project.buildDir) -} +//task("clean") { +// delete(rootProject.buildDir) +// delete(project.buildDir) +//} From 6b969c461eed75e79ee9931f65d28ea0b1bf69ed Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 17:06:29 +0100 Subject: [PATCH 06/10] Add GitHub Actions workflow for Gradle package publishing This workflow builds a Gradle package and publishes it to GitHub Packages upon release creation. --- .github/workflows/publish.yml | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..1ec7cee --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,44 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle + +name: Gradle Package + +on: + push: + tags: + - v* + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' # use the lowest version from https://en.wikipedia.org/wiki/Java_version_history#Release_table + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build the project + uses: gradle/gradle-build-action@v3 + with: + arguments: build + + # The USERNAME and TOKEN need to correspond to the credentials environment variables used in + # the publishing section of your build.gradle + - name: Publish to GitHub Packages + uses: gradle/gradle-build-action@v3 + with: + arguments: publish + env: + USERNAME: ${{ github.actor }} + TOKEN: ${{ secrets.REPO_TOKEN }} From aa814b3c1e515afb48eeb4d554daf6630a335dd4 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 17:06:47 +0100 Subject: [PATCH 07/10] Disable tag-based triggers in publish.yml Comment out the tags section in the publish workflow. --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1ec7cee..92c957b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,8 +9,8 @@ name: Gradle Package on: push: - tags: - - v* + # tags: + # - v* jobs: build: From 939f599b0019f39525843bc866141bbc424dc487 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 17:17:32 +0100 Subject: [PATCH 08/10] d --- build.gradle.kts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 70a5ebc..d4f3770 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -44,19 +44,22 @@ val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) val tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) -val finalVersion = System.getenv("version") ?: tag.drop(1) ?: "1.0.0" +version = System.getenv("version") ?: tag.drop(1).ifEmpty { + branch +} + +val finalVersion = version val finalGroup = System.getenv("group") ?: "com.dzeio" val artifact = System.getenv("artifact") ?: "crashhandler" group = finalGroup -version = finalVersion publishing { publications { create("maven") { groupId = finalGroup artifactId = artifact - version = finalVersion + version = finalVersion as String from(components["java"]) From ba3b6a3f50ce042816ef6a6e93502b82c099af5c Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 10 Mar 2026 17:31:00 +0100 Subject: [PATCH 09/10] chore: change publish token --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 92c957b..f49a403 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -41,4 +41,4 @@ jobs: arguments: publish env: USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.REPO_TOKEN }} + TOKEN: ${{ secrets.PUBLISH_TOKEN }} From 5758024298ff961dbe12668d3ee0c3778b66c279 Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 11 Mar 2026 11:03:18 +0100 Subject: [PATCH 10/10] feat: finaly able to publish to central ! --- .github/workflows/publish.yml | 55 ++++++++----------- build.gradle.kts | 89 +------------------------------ library/build.gradle.kts | 99 ++++++++++++++++++++++++++--------- 3 files changed, 96 insertions(+), 147 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f49a403..edd4828 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,44 +1,31 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle - -name: Gradle Package +name: Publish to Maven Central on: push: - # tags: - # - v* + tags: + - v* jobs: - build: - + publish: + name: Publish release runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' # use the lowest version from https://en.wikipedia.org/wiki/Java_version_history#Release_table - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file + - name: Checkout + uses: actions/checkout@v4 - - name: Build the project - uses: gradle/gradle-build-action@v3 - with: - arguments: build + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle - - name: Publish to GitHub Packages - uses: gradle/gradle-build-action@v3 - with: - arguments: publish - env: - USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.PUBLISH_TOKEN }} + - name: Publish library to Maven Central + run: ./gradlew :library:publishAndReleaseToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SIGNING_PASSWORD }} diff --git a/build.gradle.kts b/build.gradle.kts index d4f3770..6384d15 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,91 +15,4 @@ plugins { id("com.android.application") version "8.1.1" apply false id("com.android.library") version "8.1.1" apply false id("org.jetbrains.kotlin.android") version "1.7.0" apply false - - // Apply the java-library plugin for API and implementation separation. - `java-library` - `maven-publish` -} - -// from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 -fun String.runCommand( - workingDir: File = File("."), - timeoutAmount: Long = 60, - timeoutUnit: TimeUnit = TimeUnit.SECONDS -): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) - .directory(workingDir) - .redirectOutput(ProcessBuilder.Redirect.PIPE) - .redirectError(ProcessBuilder.Redirect.PIPE) - .start() - .apply { waitFor(timeoutAmount, timeoutUnit) } - .run { - val error = errorStream.bufferedReader().readText().trim() - if (error.isNotEmpty()) { - return@run "" - } - inputStream.bufferedReader().readText().trim() - } - -val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) -val tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) -val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) - -version = System.getenv("version") ?: tag.drop(1).ifEmpty { - branch -} - -val finalVersion = version -val finalGroup = System.getenv("group") ?: "com.dzeio" -val artifact = System.getenv("artifact") ?: "crashhandler" - -group = finalGroup - -publishing { - publications { - create("maven") { - groupId = finalGroup - artifactId = artifact - version = finalVersion as String - - from(components["java"]) - - pom { - name.set("Crash Handler") - description.set("Library that help handling crashes") - url.set("https://github.com/dzeiocom/crashhandler") - licenses { - license { - name.set("MIT License") - url.set("https://github.com/dzeiocom/crashhandler/blob/master/LICENSE") - } - } - developers { - developer { - id.set("avior") - name.set("Avior") - email.set("contact@dze.io") - } - } - scm { - connection.set("scm:git@github.com:dzeiocom/crashhandler.git") - url.set("https://github.com/dzeiocom/crashhandler") - } - } - } - } - repositories { - maven { - name = "GithubPackages" - url = uri("https://maven.pkg.github.com/dzeiocom/crashhandler") - credentials { - username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") - password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") - } - } - } -} - -//task("clean") { -// delete(rootProject.buildDir) -// delete(project.buildDir) -//} +} \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 71a4c7d..f895c98 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,30 +1,42 @@ +import com.vanniktech.maven.publish.SonatypeHost + plugins { id("com.android.library") - `maven-publish` kotlin("android") + id("com.vanniktech.maven.publish") version "0.29.0" } -val artifact = "crashhandler" -group = "com.dzeio" -val projectVersion = project.findProperty("version") as String? ?: "1.1.0" -version = projectVersion - -publishing { - publications { - register("release") { - groupId = group as String? - artifactId = artifact - version = projectVersion - - afterEvaluate { - from(components["release"]) - } +// from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 +fun String.runCommand( + workingDir: File = File("."), + timeoutAmount: Long = 60, + timeoutUnit: TimeUnit = TimeUnit.SECONDS +): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) + .directory(workingDir) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.PIPE) + .start() + .apply { waitFor(timeoutAmount, timeoutUnit) } + .run { + val error = errorStream.bufferedReader().readText().trim() + if (error.isNotEmpty()) { + return@run "" } + inputStream.bufferedReader().readText().trim() } + +val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) +val tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) +val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) + +val libGroup = "com.dzeio" +val libArtifact = "crashhandler" +val libVersion = System.getenv("version") ?: tag.drop(1).ifEmpty { + project.findProperty("VERSION_NAME") as String? ?: "1.1.0" } android { - namespace = "$group.$artifact" + namespace = "$libGroup.$libArtifact" compileSdk = 33 buildToolsVersion = "33.0.0" @@ -37,20 +49,13 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") - buildConfigField("String", "VERSION", "\"$projectVersion\"") + buildConfigField("String", "VERSION", "\"$libVersion\"") } testFixtures { enable = true } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } - buildTypes { getByName("release") { isMinifyEnabled = false @@ -65,6 +70,7 @@ android { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } + kotlinOptions { jvmTarget = "11" } @@ -75,6 +81,49 @@ android { } } +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + + signAllPublications() + + coordinates(libGroup, libArtifact, libVersion) + + pom { + name.set("Crash Handler") + description.set("An Android library that helps handling and reporting crashes gracefully.") + url.set("https://github.com/dzeiocom/crashhandler") + inceptionYear.set("2022") + + licenses { + license { + name.set("MIT License") + url.set("https://github.com/dzeiocom/crashhandler/blob/master/LICENSE") + distribution.set("repo") + } + } + + developers { + developer { + id.set("avior") + name.set("Avior") + email.set("contact@dze.io") + url.set("https://github.com/Aviortheking") + } + } + + scm { + url.set("https://github.com/dzeiocom/crashhandler") + connection.set("scm:git:git://github.com/dzeiocom/crashhandler.git") + developerConnection.set("scm:git:ssh://git@github.com/dzeiocom/crashhandler.git") + } + + issueManagement { + system.set("GitHub Issues") + url.set("https://github.com/dzeiocom/crashhandler/issues") + } + } +} + dependencies { // Necessary for the Activity (well to make it pretty :D) implementation("com.google.android.material:material:1.8.0")