Skip to content

Commit

Permalink
Update to use Gradle Nexus Publish Plugin (#70)
Browse files Browse the repository at this point in the history
* Update publish plugin
  • Loading branch information
sarahkoop authored Sep 21, 2023
1 parent e140bb6 commit 40e9160
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
- name: Publish Browser Switch
run: ./ci publish release
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

Expand Down
74 changes: 6 additions & 68 deletions browser-switch/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
plugins {
id 'com.android.library'
id 'maven-publish'
id 'signing'
}

android {
Expand Down Expand Up @@ -40,73 +38,13 @@ dependencies {

// region signing and publishing

task javadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}

task javadocsJar(type: Jar, dependsOn: javadocs) {
archiveClassifier.set('javadoc')
from javadocs.destinationDir
}

task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}

signing {
required {
!version.endsWith("SNAPSHOT")
}
sign publishing.publications
}

publishing {
publications {
release(MavenPublication) {
afterEvaluate {
from components.release
}
project.ext.name = "browser-switch"
project.ext.pom_name = "browser-switch"
project.ext.group_id = "com.braintreepayments.api"
project.ext.version = rootProject.version
project.ext.pom_desc = "Android Browser Switch makes it easy to open a url in a browser or Chrome Custom Tab and receive a response as the result of user interaction, either cancel or response data from the web page."

groupId = 'com.braintreepayments.api'
artifactId = 'browser-switch'
version = rootProject.versionName

artifact sourcesJar
artifact javadocsJar

pom {
name = 'browser-switch'
packaging = 'aar'
description = 'Android Browser Switch makes it easy to open a url in a browser or Chrome Custom Tab and receive a response as the result of user interaction, either cancel or response data from the web page.'
url = 'https://github.com/braintree/browser-switch-android'

scm {
url = 'scm:[email protected]:braintree/browser-switch-android.git'
connection = 'scm:[email protected]:braintree/browser-switch-android.git'
developerConnection = 'scm:[email protected]:braintree/browser-switch-android.git'
}

developers {
developer {
id = 'devs'
name = 'Braintree Payments'
}
}

licenses {
license {
name = 'MIT'
url = 'http://opensource.org/licenses/MIT'
distribution = 'repo'
}
}
}
}
}
}
apply from: rootProject.file("gradle/gradle-publish.gradle")

// endregion

8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ ext {
versionName = version
}

ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') ?: ''
ext["signing.password"] = System.getenv('SIGNING_KEY_PASSWORD') ?: ''
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_KEY_FILE') ?: ''

allprojects {
repositories {
mavenCentral()
Expand All @@ -52,8 +48,8 @@ allprojects {
nexusPublishing {
repositories {
sonatype {
username = System.getenv('SONATYPE_USERNAME')
password = System.getenv('SONATYPE_PASSWORD')
username = System.getenv('SONATYPE_NEXUS_USERNAME') ?: ''
password = System.getenv('SONATYPE_NEXUS_PASSWORD') ?: ''
}
}
transitionCheckOptions {
Expand Down
4 changes: 2 additions & 2 deletions ci
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ case $command_name in
;;
publish)
# Ref: https://nickjanetakis.com/blog/prevent-unset-variables-in-your-shell-bash-scripts-with-set-nounset
[ -n "${SONATYPE_USERNAME}" ] || (echo "::error:: SONATYPE_USERNAME env variable not set" && exit 1)
[ -n "${SONATYPE_PASSWORD}" ] || (echo "::error:: SONATYPE_PASSWORD env variable not set" && exit 1)
[ -n "${SONATYPE_NEXUS_USERNAME}" ] || (echo "::error:: SONATYPE_NEXUS_USERNAME env variable not set" && exit 1)
[ -n "${SONATYPE_NEXUS_PASSWORD}" ] || (echo "::error:: SONATYPE_NEXUS_PASSWORD env variable not set" && exit 1)
[ -n "${SIGNING_KEY_ID}" ] || (echo "::error:: SIGNING_KEY_ID env variable not set" && exit 1)
[ -n "${SIGNING_KEY_PASSWORD}" ] || (echo "::error:: SIGNING_KEY_PASSWORD env variable not set" && exit 1)
[ -n "${SIGNING_KEY_FILE}" ] || (echo "::error:: SIGNING_KEY_FILE env variable not set" && exit 1)
Expand Down
16 changes: 16 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@ android.useAndroidX=true

# Ref: https://stackoverflow.com/a/50673210
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

POM_PACKAGING=aar

POM_URL=https://github.com/braintree/browser-switch-android

POM_SCM_URL=scm:[email protected]:braintree/browser-switch-android.git
POM_SCM_CONNECTION=scm:[email protected]:braintree/browser-switch-android.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:braintree/browser-switch-android.git

POM_LICENSE_NAME=MIT
POM_LICENSE_URL=http://opensource.org/licenses/MIT
POM_LICENSE_DISTRIBUTION=repo

POM_DEVELOPER_ID=devs
POM_DEVELOPER_NAME=Braintree Payments
POM_DEVELOPER_EMAIL=[email protected]
75 changes: 75 additions & 0 deletions gradle/gradle-publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'


ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') ?: ''
ext["signing.password"] = System.getenv('SIGNING_KEY_PASSWORD') ?: ''
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_KEY_FILE') ?: ''

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId project.ext.group_id
version project.ext.version
artifactId project.ext.name
from components.release
artifact androidSourcesJar
artifact javadocsJar

pom {
name = project.ext.pom_name ?: ''
packaging = POM_PACKAGING
description = project.ext.pom_desc ?: ''
url = POM_URL
licenses {
license {
name = POM_LICENSE_NAME
url = POM_LICENSE_URL
distribution = POM_LICENSE_DISTRIBUTION
}
}
developers {
developer {
id = POM_DEVELOPER_ID
name = POM_DEVELOPER_NAME
email = POM_DEVELOPER_EMAIL
}
}
scm {
connection = POM_SCM_CONNECTION
developerConnection = POM_SCM_DEV_CONNECTION
url = POM_SCM_URL
}
}
}
}
}

signing {
sign publishing.publications
sign configurations.archives
}
}

task javadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}

task javadocsJar(type: Jar, dependsOn: javadocs) {
archiveClassifier.set('javadoc')
from javadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
}

artifacts {
archives androidSourcesJar
archives javadocsJar
}

0 comments on commit 40e9160

Please sign in to comment.