Skip to content

Commit

Permalink
Merge pull request #1 from canopas/publish-to-maven-central
Browse files Browse the repository at this point in the history
Publish to maven central
  • Loading branch information
cp-radhika-s authored Feb 26, 2022
2 parents 3ec9850 + 9b6da63 commit 400326d
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/app-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Android Build

on: [ push ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 11
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 11
- name: Build with Gradle
run: ./gradlew build
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish
on:
push:
tags:
- '*'

jobs:
publish:
name: Release build and publish
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 11

- name: Publish to MavenCentral
run: ./gradlew countrypicker:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.iml
.gradle
.idea
/local.properties
/.idea/caches
/.idea/libraries
Expand Down
117 changes: 117 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ buildscript {
ext {
compose_version = '1.1.0-beta04'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.0' apply false
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}
apply from: "${rootDir}/scripts/publish-root.gradle"

task clean(type: Delete) {
delete rootProject.buildDir
Expand Down
7 changes: 7 additions & 0 deletions countrypicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ plugins {
id 'kotlin-android'
}

ext {
PUBLISH_GROUP_ID = 'com.canopas.jetcountrypicker'
PUBLISH_VERSION = '1.0.0'
PUBLISH_ARTIFACT_ID = 'jetcountrypicker'
}
apply from: "${rootDir}/scripts/publish-module.gradle"

android {
compileSdk 31

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jan 25 12:25:52 IST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
78 changes: 78 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
} else {
from sourceSets.main.java.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 set up 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 {
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}

artifact androidSourcesJar

// Mostly self-explanatory metadata
pom {
name = PUBLISH_ARTIFACT_ID
description = 'Country code bottomsheet picker in Jetpack Compose'
url = 'https://github.com/canopas/JetCountrypicker'
licenses {
license {
name = 'License'
url = 'https://github.com/canopas/JetCountrypicker/blob/main/License'
}
}
developers {
developer {
id = 'cp-radhika-s'
name = 'Radhika canopas'
email = 'radhika.s@canopas.com'
}
// Add all other devs here...
}

// Version control info - if you're using GitHub, follow the
// format as seen here
scm {
connection = 'scm:git:github.com/canopas/JetCountrypicker.git'
developerConnection = 'scm:git:ssh://github.com/canopas/JetCountrypicker.git'
url = 'https://github.com/canopas/JetCountrypicker.git'
}
}
}
}
}
}
signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"],
)

sign publishing.publications
}
44 changes: 44 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Create variables with empty default values
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.key"] = ''
ext["snapshot"] = ''

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('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')
ext["snapshot"] = System.getenv('SNAPSHOT')
}

// 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/"))
}
}
}
8 changes: 7 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "JetCountyPicker"
Expand Down

0 comments on commit 400326d

Please sign in to comment.