diff --git a/.github/workflows/uploadArchives.yml b/.github/workflows/uploadArchives.yml index 3e223c18..c8a6bbbd 100644 --- a/.github/workflows/uploadArchives.yml +++ b/.github/workflows/uploadArchives.yml @@ -31,18 +31,23 @@ jobs: java-version: 17.0.10 distribution: "adopt" cache: gradle - - - name: Add Maven credentials to gradle.properties - run: echo "NEXUS_USERNAME=${{ secrets.NEXUS_USERNAME }}" >> gradle.properties && echo "NEXUS_PASSWORD=${{ secrets.NEXUS_PASSWORD }}" >> gradle.properties + + - name: Add Maven Central Repository credentials and keys to gradle.properties + run: | + echo "mavenCentralUsername=${{ secrets.OSSRH_USERNAME }}" >> gradle.properties + echo "mavenCentralPassword=${{ secrets.OSSRH_PASSWORD }}" >> gradle.properties + echo "signing.keyId=${{ secrets.SIGNING_KEY_ID }}" >> gradle.properties + echo "signing.password=${{ secrets.SIGNING_PASSWORD }}" >> gradle.properties + echo "signing.secretKeyRingFile=secret_key.gpg" >> gradle.properties + + - name: Prepare signing secret key ring file + run: echo "${{ secrets.SIGNING_KEY }}" | base64 --decode > backtrace-library/secret_key.gpg - name: Grant execute permission for gradlew run: chmod +x gradlew - - - name: Upload archives - run: ./gradlew build publish - env: - ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ASCII_ARMORED_GPG_KEY }} # ASCII-armored GPG key - ORG_GRADLE_PROJECT_signingPassword: "" # Using empty password for GPG key + + - name: Build and upload + run: ./gradlew build publishAllPublicationsToMavenCentralRepository - uses: xresloader/upload-to-github-release@v1 env: diff --git a/backtrace-library/build.gradle b/backtrace-library/build.gradle index 8007fa12..da80597d 100644 --- a/backtrace-library/build.gradle +++ b/backtrace-library/build.gradle @@ -1,8 +1,11 @@ plugins { id 'com.gladed.androidgitversion' version '0.4.14' + id "com.vanniktech.maven.publish" version "0.29.0" apply true } apply plugin: 'com.android.library' +import com.vanniktech.maven.publish.SonatypeHost + androidGitVersion { // this is the format for generating the versionName // default is %tag%%-count%%-commit%%-branch%%-dirty% - removed %-dirty% because submodules tend to get dirty @@ -34,12 +37,6 @@ android { buildFeatures { buildConfig = true } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } } buildTypes { @@ -74,6 +71,43 @@ android { } } +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + signAllPublications() + coordinates(GROUP, POM_NAME, android.defaultConfig.versionName) + + pom { + name = POM_NAME + description = POM_DESCRIPTION + url = POM_URL + + licenses { + license { + name = POM_LICENSE_NAME + url = POM_LICENSE_URL + distribution = POM_LICENSE_DIST + } + } + + developers { + developer { + id = POM_DEVELOPER_ID + name = POM_DEVELOPER_NAME + } + developer { + id = POM_DEVELOPER_ID2 + name = POM_DEVELOPER_NAME2 + } + } + + scm { + url = POM_SCM_URL + connection = POM_SCM_CONNECTION + developerConnection = POM_SCM_DEV_CONNECTION + } + } +} + dependencies { implementation 'com.google.code.gson:gson:2.12.1' implementation 'androidx.appcompat:appcompat:1.6.1' @@ -90,5 +124,3 @@ dependencies { androidTestImplementation 'org.mockito:mockito-core:5.16.0' androidTestImplementation "org.mockito:mockito-android:5.16.0" } - -apply from: 'publish.gradle' diff --git a/backtrace-library/publish.gradle b/backtrace-library/publish.gradle deleted file mode 100644 index 0b03f57d..00000000 --- a/backtrace-library/publish.gradle +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2013 Chris Banes - * - * 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. - * - * source: https://github.com/chrisbanes/gradle-mvn-push - */ - -apply plugin: 'maven-publish' -apply plugin: 'signing' - -version = android.defaultConfig.versionName -group = GROUP - -def isReleaseBuild() { - return version.contains("SNAPSHOT") == false -} - -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -def getRepositoryUsername() { - return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" -} - -def getRepositoryPassword() { - return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" -} - -def configurePom(pom) { - pom.name = POM_NAME - pom.packaging = POM_PACKAGING - pom.description = POM_DESCRIPTION - pom.url = POM_URL - - pom.scm { - url = POM_SCM_URL - connection = POM_SCM_CONNECTION - developerConnection = POM_SCM_DEV_CONNECTION - } - - pom.licenses { - license { - name = POM_LICENSE_NAME - url = POM_LICENSE_URL - distribution = POM_LICENSE_DIST - } - } - - pom.developers { - developer { - id = POM_DEVELOPER_ID - name = POM_DEVELOPER_NAME - } - developer { - id = POM_DEVELOPER_ID2 - name = POM_DEVELOPER_NAME2 - } - } -} - -afterEvaluate { project -> - publishing { - publications { - release(MavenPublication) { - from components.release - groupId GROUP - artifactId POM_ARTIFACT_ID - version version - } - } - - repositories { - maven { - def releasesRepoUrl = getReleaseRepositoryUrl() - def snapshotsRepoUrl = getSnapshotRepositoryUrl() - url = isReleaseBuild() ? releasesRepoUrl : snapshotsRepoUrl - - credentials(PasswordCredentials) { - username = getRepositoryUsername() - password = getRepositoryPassword() - } - } - } - } - - publishing.publications.all { publication -> - publication.groupId = GROUP - publication.version = version - - configurePom(publication.pom) - } - - signing { - if (findProperty("signingKey")) { - def signingKey = findProperty("signingKey") - def signingPassword = findProperty("signingPassword") - useInMemoryPgpKeys(signingKey, signingPassword) - } - - publishing.publications.all { publication -> - sign publication - } - } -} diff --git a/gradle.properties b/gradle.properties index 577e1a3f..cc0bfdaf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx1024m # org.gradle.parallel=true GROUP=com.github.backtrace-labs.backtrace-android - +POM_NAME=backtrace-library POM_DESCRIPTION=Backtrace's integration with Android applications written in Java allows customers to capture and report handled and unhandled java exceptions. POM_URL=https://github.com/backtrace-labs/backtrace-android POM_SCM_URL=https://github.com/backtrace-labs/backtrace-android