Skip to content

Commit 91808f7

Browse files
authored
Maven Central Deployment (#88)
* Updated deployment to use Maven Central & Prepared for a 2.1.0 (Central) release
1 parent 96ca157 commit 91808f7

8 files changed

Lines changed: 224 additions & 130 deletions

File tree

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Release"
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
jobs:
8+
publish:
9+
name: "Release"
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- name: "Checkout"
13+
uses: actions/checkout@v2
14+
- name: "Setup JDK"
15+
uses: actions/setup-java@v2
16+
with:
17+
distribution: 'temurin'
18+
java-version: '11'
19+
cache: 'gradle'
20+
- name: "Build & Release"
21+
run: ./gradlew clean library:assembleRelease androidJavaDocJar androidSourcesJar generatePomFileForNexusPublication publishNexusPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
22+
env:
23+
SONATYPE_TOKEN_USERNAME: ${{ secrets.SONATYPE_TOKEN_USERNAME }}
24+
SONATYPE_TOKEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }}
25+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
26+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
27+
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ The PlaylistCore documentation website can be found on the website linked above
1313

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

1918
```gradle
2019
repositories {
21-
jcenter();
20+
mavenCentral()
2221
}
2322
2423
dependencies {
2524
//...
26-
compile 'com.devbrackets.android:playlistcore:2.0.1'
25+
compile 'com.devbrackets.android:playlistcore:2.1.0'
2726
}
2827
```
2928

29+
###### NOTE: for versions before 2.1.0 see [JCenter][JCenter]
30+
3031
Example
3132
-------
3233
Due to the length an example would be, please see the Demo app
@@ -61,6 +62,7 @@ Attribution
6162
[Design Icons]: https://github.com/google/material-design-icons
6263
[CC 4.0]: http://creativecommons.org/licenses/by/4.0/
6364
[JCenter]: https://bintray.com/brianwernick/maven/PlaylistCore/view#files
65+
[Maven Central]: https://s01.oss.sonatype.org/#nexus-search;quick~com.devbrackets.android.playlistcore
6466
[Website]: http://devbrackets.com/dev/libs/playlistcore.html
6567
[Java Docs]: http://devbrackets.com/dev/libs/docs/playlistcore/1.1.0/index.html
6668
[Apache 2.0]: https://opensource.org/licenses/Apache-2.0

build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ buildscript {
1212
}
1313
}
1414

15+
plugins {
16+
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
17+
}
18+
1519
allprojects {
1620
repositories {
1721
google()
@@ -24,4 +28,31 @@ allprojects {
2428
}
2529
}
2630
}
31+
}
32+
33+
/*
34+
* Below is the functionality to publish the `library` module to Maven Central (Sonatype) using the
35+
* plugin `io.github.gradle-nexus.publish-plugin`. This functionality is included in this (root)
36+
* `build.gradle` because that's what the plugin expects; if this changes in the future then we
37+
* should migrate this functionality into the `publish.gradle` file instead.
38+
*/
39+
apply from: 'gradle/release/libraryInfo.gradle'
40+
41+
ext {
42+
libraryInfo = getLibraryInfo()
43+
}
44+
45+
// Used by the publish-plugin
46+
group = libraryInfo.groupId
47+
version = libraryInfo.versionName
48+
49+
nexusPublishing {
50+
repositories {
51+
sonatype {
52+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
53+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
54+
username = System.getenv("SONATYPE_TOKEN_USERNAME")
55+
password = System.getenv("SONATYPE_TOKEN_PASSWORD")
56+
}
57+
}
2758
}

gradle/release/libraryInfo.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class LibraryInfo {
2+
String artifactId
3+
String groupId
4+
5+
Integer versionMajor
6+
Integer versionMinor
7+
Integer versionPatch
8+
String versionName
9+
}
10+
11+
def readLibraryProps() {
12+
def versionProps = new Properties()
13+
def file = new File("$projectDir/libraryInfo.properties")
14+
versionProps.load(file.newInputStream())
15+
16+
return versionProps
17+
}
18+
19+
def getLibraryInfo() {
20+
def props = readLibraryProps()
21+
LibraryInfo info = new LibraryInfo()
22+
23+
info.artifactId = props.get('ARTIFACT_ID') as String
24+
info.groupId = props.get('GROUP_ID') as String
25+
26+
info.versionMajor = props.get('VERSION_MAJOR') as Integer
27+
info.versionMinor = props.get('VERSION_MINOR') as Integer
28+
info.versionPatch = props.get('VERSION_PATCH') as Integer
29+
info.versionName = "${info.versionMajor}.${info.versionMinor}.${info.versionPatch}"
30+
31+
return info
32+
}
33+
34+
ext {
35+
getLibraryInfo = this.&getLibraryInfo
36+
}

gradle/release/publish.gradle

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
apply plugin: "maven-publish"
3+
apply plugin: "signing"
4+
5+
task androidJavaDoc(type: Javadoc) {
6+
source = android.sourceSets.main.java.srcDirs
7+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
8+
options.encoding "UTF-8"
9+
options.charSet 'UTF-8'
10+
options.author true
11+
options.version true
12+
failOnError false
13+
}
14+
15+
task androidJavaDocJar(type: Jar, dependsOn: androidJavaDoc) {
16+
archiveClassifier.set('javadoc')
17+
from androidJavaDoc.destinationDir
18+
}
19+
20+
task androidSourcesJar(type: Jar) {
21+
archiveClassifier.set('sources')
22+
from android.sourceSets.main.java.srcDirs
23+
}
24+
25+
/**
26+
* Helper to add dependencies to the POM node. This is needed during manual construction
27+
* of the dependencies block
28+
*/
29+
static def addPomDependency(groovy.util.Node dependenciesNode, Dependency dependency, String dependencyScope) {
30+
// Ignore incomplete dependencies
31+
if (dependency.name == null || dependency.name == 'unspecified' || dependency.group == null || dependency.version == null) {
32+
return
33+
}
34+
35+
def dependencyNode = dependenciesNode.appendNode('dependency')
36+
dependencyNode.appendNode('groupId', dependency.group)
37+
dependencyNode.appendNode('artifactId', dependency.name)
38+
dependencyNode.appendNode('version', dependency.version)
39+
dependencyNode.appendNode('scope', dependencyScope)
40+
}
41+
42+
/**
43+
* Deploy to Maven Central (Sonatype)
44+
* `$ ./gradlew clean library:assembleRelease androidJavaDocJar androidSourcesJar generatePomFileForNexusPublication publishNexusPublicationToSonatypeRepository closeSonatypeStagingRepository`
45+
*
46+
* ** NOTE: **
47+
* This expects the following environment variables to be present
48+
* - `SONATYPE_TOKEN_USERNAME` : The username for the user token in Sonatype
49+
* - `SONATYPE_TOKEN_PASSWORD` : The password for the user token in Sonatype
50+
* - `SIGNING_KEY_ID` : The ID for the GPG signing key to sign the library with
51+
* - `SIGNING_KEY` : The GPG key to sign the library with
52+
* - `SIGNING_KEY_PASSWORD` : The password for the `SIGNING_KEY`
53+
*/
54+
publishing {
55+
publications {
56+
nexus(MavenPublication) {
57+
groupId rootProject.ext.libraryInfo.groupId
58+
artifactId rootProject.ext.libraryInfo.artifactId
59+
version rootProject.ext.libraryInfo.versionName
60+
61+
artifact bundleReleaseAar
62+
artifact androidJavaDocJar
63+
artifact androidSourcesJar
64+
65+
pom {
66+
name = rootProject.ext.libraryInfo.groupId + ":" + rootProject.ext.libraryInfo.artifactId
67+
description = "A media playback management library for Android"
68+
url = "https://github.com/brianwernick/PlaylistCore"
69+
licenses {
70+
license {
71+
name = "The Apache License, Version 2.0"
72+
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
73+
}
74+
}
75+
scm {
76+
connection = 'scm:git:github.com/brianwernick/PlaylistCore.git'
77+
developerConnection = 'scm:git:ssh://github.com/brianwernick/PlaylistCore.git'
78+
url = 'https://github.com/brianwernick/PlaylistCore/tree/main'
79+
}
80+
developers {
81+
developer {
82+
name = 'Brian Wernick'
83+
email = 'brian@devbrackets.com'
84+
organization = 'DevBrackets'
85+
organizationUrl = 'https://devbrackets.com'
86+
}
87+
}
88+
89+
// The generated POM doesn't include dependencies when building Android artifacts, so we manually
90+
// add the dependencies to the POM here
91+
withXml {
92+
def dependenciesNode = asNode().appendNode('dependencies')
93+
94+
// Iterate over the implementation dependencies, adding a <dependency> node for each
95+
configurations.implementation.dependencies.each {
96+
addPomDependency(dependenciesNode, it, "runtime")
97+
}
98+
99+
// Iterate over the api dependencies, adding a <dependency> node for each
100+
configurations.api.dependencies.each {
101+
addPomDependency(dependenciesNode, it, "compile")
102+
}
103+
}
104+
}
105+
}
106+
}
107+
}
108+
109+
signing {
110+
useInMemoryPgpKeys(
111+
System.getenv("SIGNING_KEY_ID"),
112+
System.getenv("SIGNING_KEY"),
113+
System.getenv("SIGNING_KEY_PASSWORD"),
114+
)
115+
116+
sign publishing.publications.nexus
117+
}

library/build.gradle

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,7 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33

44
afterEvaluate {
5-
apply from: 'gradle/publish.gradle'
6-
}
7-
8-
/**
9-
* Holds the information associated with the library needed for the
10-
* bintray plugin to publish the artifact
11-
*/
12-
class LibraryInfo {
13-
static Integer versionMajor = 2
14-
static Integer versionMinor = 0
15-
static Integer versionPatch = 1
16-
17-
static String artifactId = 'playlistcore'
18-
static String groupId = 'com.devbrackets.android'
19-
static String versionName = "${versionMajor}.${versionMinor}.${versionPatch}"
20-
static Integer versionCode = versionMajor * 10_000 + versionMinor * 1_000 + versionPatch * 100
21-
}
22-
23-
static def getLibraryInfo() {
24-
return new LibraryInfo()
5+
apply from: '../gradle/release/publish.gradle'
256
}
267

278
dependencies {

library/gradle/publish.gradle

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)