Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,26 @@ jobs:

- name: Build with Gradle
run: ./gradlew build

publish:
name: Publish to Maven Central
if: "github.event.release || github.event.release.prerelease"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Setup credentials
run: |
echo $GPG_KEY_FILE | base64 --decode > secring.gpg
echo $GRADLE_PROPERTIES_FILE | base64 --decode > gradle.properties
echo 'Setup credentials successfuly!'

- name: Publish package
run: ./gradlew publishReleasePublicationToSonatypeRepository
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13.2'
}

ext {
PUBLISH_GROUP_ID = 'io.github.felipebonezi'
PUBLISH_VERSION = '1.0.0'
PUBLISH_ARTIFACT_ID = 'android-printer-lib'
}
apply from: 'publish-remote.gradle'
86 changes: 86 additions & 0 deletions app/publish-remote.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'


task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
// For android libraries
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
// For pure kotlin libraries, in case you have them
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
}

artifacts {
archives androidSourcesJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
// The coordinates of the library, being set from variables that
// we'll setup later
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

// Two artifacts, the `aar` (or `jar`) and the sources
// if (project.plugins.findPlugin("com.android.library")) {
// from components.release
// } else {
// from components.java
// }

artifact(bundleReleaseAar)
// artifacts javaDocJar

// Mostly self-explanatory metadata
pom {
name = PUBLISH_ARTIFACT_ID
description = "Android printer library"
url = 'https://github.com/felipebonezi/android-printer-lib'
licenses {
license {
name = 'Apache 2.0 license'
url = 'https://opensource.org/license/apache-2-0/'
}
}
developers {
developer {
id = 'felipebonezi'
name = 'Felipe Bonezi'
email = 'felipebonezi@gmail.com'
url = 'https://github.com/sponsor/felipebonezi'
}
}

// Version control info
scm {
connection = 'scm:git:git://github.com/felipebonezi/android-printer-lib.git'
developerConnection = 'scm:git:ssh://github.com/felipebonezi/android-printer-lib.git'
url = 'http://github.com/felipebonezi/android-printer-lib'
}
}

}
}
}
}


signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"]
)
sign publishing.publications
}
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ buildscript {
}
}

plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
apply from: 'scripts/publish-root.gradle'

allprojects {
repositories {
google()
Expand Down
43 changes: 43 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Create variables with empty default values
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.key"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''


File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is ->
p.load(is)
}
p.each {name, value ->
ext[name] = value
}
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('SONATYPE_USERNAME')
ext["ossrhPassword"] = System.getenv('SONATYPE_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext['signing.keyId'] = System.getenv('GPG_KEY_ID')
ext['signing.password'] = System.getenv('SONATYPE_PASSWORD')
ext["signing.key"] = System.getenv('GPG_KEY_FILE')
}



// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}