Skip to content

Commit

Permalink
Maven Central Deployment (#88)
Browse files Browse the repository at this point in the history
* Updated deployment to use Maven Central & Prepared for a 2.1.0 (Central) release
  • Loading branch information
brianwernick authored May 2, 2022
1 parent 96ca157 commit 91808f7
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 130 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Release"

on:
release:
types: [released]

jobs:
publish:
name: "Release"
runs-on: ubuntu-20.04
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Setup JDK"
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'
- name: "Build & Release"
run: ./gradlew clean library:assembleRelease androidJavaDocJar androidSourcesJar generatePomFileForNexusPublication publishNexusPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
env:
SONATYPE_TOKEN_USERNAME: ${{ secrets.SONATYPE_TOKEN_USERNAME }}
SONATYPE_TOKEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ The PlaylistCore documentation website can be found on the website linked above

Use
-------
The latest AAR (Android Archive) files can be downloaded from [JCenter][JCenter]
Or included in your gradle dependencies
The latest version can be included from [Maven Central][Maven Central].

```gradle
repositories {
jcenter();
mavenCentral()
}
dependencies {
//...
compile 'com.devbrackets.android:playlistcore:2.0.1'
compile 'com.devbrackets.android:playlistcore:2.1.0'
}
```

###### NOTE: for versions before 2.1.0 see [JCenter][JCenter]

Example
-------
Due to the length an example would be, please see the Demo app
Expand Down Expand Up @@ -61,6 +62,7 @@ Attribution
[Design Icons]: https://github.com/google/material-design-icons
[CC 4.0]: http://creativecommons.org/licenses/by/4.0/
[JCenter]: https://bintray.com/brianwernick/maven/PlaylistCore/view#files
[Maven Central]: https://s01.oss.sonatype.org/#nexus-search;quick~com.devbrackets.android.playlistcore
[Website]: http://devbrackets.com/dev/libs/playlistcore.html
[Java Docs]: http://devbrackets.com/dev/libs/docs/playlistcore/1.1.0/index.html
[Apache 2.0]: https://opensource.org/licenses/Apache-2.0
31 changes: 31 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ buildscript {
}
}

plugins {
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
}

allprojects {
repositories {
google()
Expand All @@ -24,4 +28,31 @@ allprojects {
}
}
}
}

/*
* Below is the functionality to publish the `library` module to Maven Central (Sonatype) using the
* plugin `io.github.gradle-nexus.publish-plugin`. This functionality is included in this (root)
* `build.gradle` because that's what the plugin expects; if this changes in the future then we
* should migrate this functionality into the `publish.gradle` file instead.
*/
apply from: 'gradle/release/libraryInfo.gradle'

ext {
libraryInfo = getLibraryInfo()
}

// Used by the publish-plugin
group = libraryInfo.groupId
version = libraryInfo.versionName

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username = System.getenv("SONATYPE_TOKEN_USERNAME")
password = System.getenv("SONATYPE_TOKEN_PASSWORD")
}
}
}
36 changes: 36 additions & 0 deletions gradle/release/libraryInfo.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class LibraryInfo {
String artifactId
String groupId

Integer versionMajor
Integer versionMinor
Integer versionPatch
String versionName
}

def readLibraryProps() {
def versionProps = new Properties()
def file = new File("$projectDir/libraryInfo.properties")
versionProps.load(file.newInputStream())

return versionProps
}

def getLibraryInfo() {
def props = readLibraryProps()
LibraryInfo info = new LibraryInfo()

info.artifactId = props.get('ARTIFACT_ID') as String
info.groupId = props.get('GROUP_ID') as String

info.versionMajor = props.get('VERSION_MAJOR') as Integer
info.versionMinor = props.get('VERSION_MINOR') as Integer
info.versionPatch = props.get('VERSION_PATCH') as Integer
info.versionName = "${info.versionMajor}.${info.versionMinor}.${info.versionPatch}"

return info
}

ext {
getLibraryInfo = this.&getLibraryInfo
}
117 changes: 117 additions & 0 deletions gradle/release/publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

apply plugin: "maven-publish"
apply plugin: "signing"

task androidJavaDoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
options.encoding "UTF-8"
options.charSet 'UTF-8'
options.author true
options.version true
failOnError false
}

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

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

/**
* Helper to add dependencies to the POM node. This is needed during manual construction
* of the dependencies block
*/
static def addPomDependency(groovy.util.Node dependenciesNode, Dependency dependency, String dependencyScope) {
// Ignore incomplete dependencies
if (dependency.name == null || dependency.name == 'unspecified' || dependency.group == null || dependency.version == null) {
return
}

def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
dependencyNode.appendNode('scope', dependencyScope)
}

/**
* Deploy to Maven Central (Sonatype)
* `$ ./gradlew clean library:assembleRelease androidJavaDocJar androidSourcesJar generatePomFileForNexusPublication publishNexusPublicationToSonatypeRepository closeSonatypeStagingRepository`
*
* ** NOTE: **
* This expects the following environment variables to be present
* - `SONATYPE_TOKEN_USERNAME` : The username for the user token in Sonatype
* - `SONATYPE_TOKEN_PASSWORD` : The password for the user token in Sonatype
* - `SIGNING_KEY_ID` : The ID for the GPG signing key to sign the library with
* - `SIGNING_KEY` : The GPG key to sign the library with
* - `SIGNING_KEY_PASSWORD` : The password for the `SIGNING_KEY`
*/
publishing {
publications {
nexus(MavenPublication) {
groupId rootProject.ext.libraryInfo.groupId
artifactId rootProject.ext.libraryInfo.artifactId
version rootProject.ext.libraryInfo.versionName

artifact bundleReleaseAar
artifact androidJavaDocJar
artifact androidSourcesJar

pom {
name = rootProject.ext.libraryInfo.groupId + ":" + rootProject.ext.libraryInfo.artifactId
description = "A media playback management library for Android"
url = "https://github.com/brianwernick/PlaylistCore"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = 'scm:git:github.com/brianwernick/PlaylistCore.git'
developerConnection = 'scm:git:ssh://github.com/brianwernick/PlaylistCore.git'
url = 'https://github.com/brianwernick/PlaylistCore/tree/main'
}
developers {
developer {
name = 'Brian Wernick'
email = '[email protected]'
organization = 'DevBrackets'
organizationUrl = 'https://devbrackets.com'
}
}

// The generated POM doesn't include dependencies when building Android artifacts, so we manually
// add the dependencies to the POM here
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

// Iterate over the implementation dependencies, adding a <dependency> node for each
configurations.implementation.dependencies.each {
addPomDependency(dependenciesNode, it, "runtime")
}

// Iterate over the api dependencies, adding a <dependency> node for each
configurations.api.dependencies.each {
addPomDependency(dependenciesNode, it, "compile")
}
}
}
}
}
}

signing {
useInMemoryPgpKeys(
System.getenv("SIGNING_KEY_ID"),
System.getenv("SIGNING_KEY"),
System.getenv("SIGNING_KEY_PASSWORD"),
)

sign publishing.publications.nexus
}
21 changes: 1 addition & 20 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

afterEvaluate {
apply from: 'gradle/publish.gradle'
}

/**
* Holds the information associated with the library needed for the
* bintray plugin to publish the artifact
*/
class LibraryInfo {
static Integer versionMajor = 2
static Integer versionMinor = 0
static Integer versionPatch = 1

static String artifactId = 'playlistcore'
static String groupId = 'com.devbrackets.android'
static String versionName = "${versionMajor}.${versionMinor}.${versionPatch}"
static Integer versionCode = versionMajor * 10_000 + versionMinor * 1_000 + versionPatch * 100
}

static def getLibraryInfo() {
return new LibraryInfo()
apply from: '../gradle/release/publish.gradle'
}

dependencies {
Expand Down
106 changes: 0 additions & 106 deletions library/gradle/publish.gradle

This file was deleted.

Loading

0 comments on commit 91808f7

Please sign in to comment.