Skip to content

Commit fbe47cc

Browse files
authored
publish to OSSRH (#115)
1 parent 074c4b3 commit fbe47cc

File tree

4 files changed

+134
-68
lines changed

4 files changed

+134
-68
lines changed

.github/workflows/android.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: Android CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '**/README.md'
9+
pull_request:
10+
branches:
11+
- master
412

513
jobs:
614
build:
@@ -20,3 +28,10 @@ jobs:
2028
with:
2129
name: pd-core-aar
2230
path: PdCore/build/outputs/aar
31+
- if: github.event_name == 'push'
32+
run: ./gradlew publishToSonatype
33+
env:
34+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
35+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
36+
#ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
37+
#ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ local.properties
3333
# Eclipse project files
3434
.classpath
3535
.project
36+
.settings/org.eclipse.buildship.core.prefs
3637

3738
# Proguard folder generated by Eclipse
3839
proguard/
@@ -45,3 +46,6 @@ proguard/
4546

4647
# NetBeans project files
4748
.nb-gradle/
49+
50+
# Code
51+
.vscode/settings.json

PdCore/build.gradle

Lines changed: 91 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
apply plugin: 'com.android.library'
2-
apply plugin: 'com.github.dcendents.android-maven'
3-
apply plugin: 'com.jfrog.bintray'
4-
5-
import org.apache.tools.ant.taskdefs.condition.Os
1+
plugins {
2+
id 'com.android.library'
3+
id 'signing'
4+
id 'maven-publish'
5+
}
66

7-
version = '1.2.1-rc2'
8-
group = 'org.puredata.android'
7+
group = rootProject.group
98
archivesBaseName = 'pd-core'
9+
version = rootProject.version
1010

1111
dependencies {
1212
api 'com.noisepages.nettoyeur:midi:1.0.0-rc1'
1313
implementation 'com.noisepages.nettoyeur:midi:1.0.0-rc1'
14-
implementation "androidx.legacy:legacy-support-v4:" + rootProject.androidxLegacySupportVersion
14+
implementation 'androidx.legacy:legacy-support-v4:' + rootProject.androidxLegacySupportVersion
1515
}
1616

1717
android {
@@ -78,11 +78,13 @@ android {
7878

7979
libraryVariants.all { variant ->
8080
variant.outputs.all { output ->
81-
outputFileName = "${archivesBaseName}-${version}.aar"
81+
outputFileName = "${archivesBaseName}.aar"
8282
}
8383
}
8484
}
8585

86+
import org.apache.tools.ant.taskdefs.condition.Os
87+
8688
// TODO: Move to convention plugin?
8789
def getNdkBuildExecutablePath() {
8890
// android.ndkDirectory should return project.android.ndkVersion ndkDirectory
@@ -95,49 +97,19 @@ def getNdkBuildExecutablePath() {
9597
return ndkBuildFullPath
9698
}
9799

98-
def siteUrl = 'https://github.com/libpd/pd-for-android'
99-
def gitUrl = 'https://github.com/libpd/pd-for-android.git'
100-
101-
install {
102-
repositories.mavenInstaller {
103-
104-
pom {
105-
project {
106-
packaging 'aar'
107-
108-
name 'Pure Data for Android'
109-
url siteUrl
110-
111-
licenses {
112-
license {
113-
name 'BSD New'
114-
url 'https://raw.githubusercontent.com/libpd/pd-for-android/master/PdCore/LICENSE.txt'
115-
}
116-
}
117-
118-
scm {
119-
connection gitUrl
120-
developerConnection gitUrl
121-
url siteUrl
122-
123-
}
124-
}
125-
}
126-
}
127-
}
128-
129100
task sourcesJar(type: Jar) {
101+
archiveClassifier.set('sources')
130102
from android.sourceSets.main.java.srcDirs
131-
classifier = 'sources'
132103
}
133104

134105
task javadoc(type: Javadoc) {
135106
source = android.sourceSets.main.java.srcDirs
136107
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
108+
failOnError = false // TODO: fix javadoc issues
137109
}
138110

139111
task javadocJar(type: Jar, dependsOn: javadoc) {
140-
classifier = 'javadoc'
112+
archiveClassifier.set('javadoc')
141113
from javadoc.destinationDir
142114
}
143115

@@ -146,29 +118,85 @@ artifacts {
146118
archives sourcesJar
147119
}
148120

149-
bintray {
150-
def localProperties = new Properties()
151-
def localPropertiesFile = rootProject.file('local.properties')
152-
if (localPropertiesFile.exists()) {
153-
localProperties.load(localPropertiesFile.newDataInputStream())
154-
user = localProperties.getProperty("bintray.user")
155-
key = localProperties.getProperty("bintray.apikey")
156-
}
121+
def siteUrl = 'https://github.com/libpd/pd-for-android'
157122

158-
if (user != null && key != null) {
159-
logger.info('Bintray user/apikey found')
160-
} else {
161-
logger.info('Bintray user/apikey not found')
123+
publishing {
124+
publications {
125+
maven(MavenPublication) {
126+
groupId group
127+
artifactId archivesBaseName
128+
version version
129+
// TODO: include aar artifact from components?
130+
artifact "${buildDir}/outputs/aar/${archivesBaseName}.aar"
131+
// ossrh requires javadoc and sources
132+
artifact sourcesJar
133+
artifact javadocJar
134+
135+
pom {
136+
name = "${project.group}:${project.archivesBaseName}"
137+
description = 'Pure Data for Android'
138+
url = siteUrl
139+
licenses {
140+
license {
141+
name = 'BSD New'
142+
url = 'https://raw.githubusercontent.com/libpd/pd-for-android/master/PdCore/LICENSE.txt'
143+
}
144+
}
145+
developers {
146+
developer {
147+
id = 'joebowbeer'
148+
name = 'Joe Bowbeer'
149+
}
150+
// TODO: Add all other devs here...
151+
}
152+
scm {
153+
connection = 'scm:git:https://github.com/libpd/pd-for-android'
154+
developerConnection = 'scm:git:ssh://github.com/libpd/pd-for-android.git'
155+
url = siteUrl
156+
}
157+
}
158+
}
162159
}
160+
}
163161

164-
configurations = ['archives']
165-
pkg {
166-
repo = "maven"
167-
name = "pd-for-android"
168-
userOrg = 'pd-for-android'
169-
websiteUrl = siteUrl
170-
vcsUrl = gitUrl
171-
licenses = ["BSD New"]
172-
publish = false
162+
// configure publishing to a local directory for testing (not necessary)
163+
// ./gradlew publishMavenPublicationToLocalRepository
164+
// tree ./PdCore/build/repos
165+
publishing {
166+
repositories {
167+
maven {
168+
name = 'local'
169+
def releasesRepoUrl = "$buildDir/repos/releases"
170+
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
171+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
172+
}
173173
}
174174
}
175+
176+
// ossrh requires signed releases, but not snapshots.
177+
// This configures signing if a key is found.
178+
// The following environment variables provide a signing key and passphrase:
179+
// export ORG_GRADLE_PROJECT_signingKey=`cat private.pgp`
180+
// export ORG_GRADLE_PROJECT_signingPassword="<passphrase>"
181+
// After making the above available, you can try signing using
182+
// ./gradlew signMavenPublication
183+
def hasSigningKey = project.hasProperty('signingKeyId') || project.hasProperty('signingKey')
184+
if (hasSigningKey) {
185+
sign(project)
186+
}
187+
void sign(Project project) {
188+
project.signing {
189+
required { project.gradle.taskGraph.hasTask('required') }
190+
def signingKeyId = project.findProperty('signingKeyId')
191+
def signingKey = project.findProperty('signingKey')
192+
def signingPassword = project.findProperty('signingPassword')
193+
if (signingKeyId) {
194+
// use in-memory ascii-armored OpenPGP subkey
195+
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
196+
} else if (signingKey) {
197+
// use in-memory ascii-armored key
198+
useInMemoryPgpKeys(signingKey, signingPassword)
199+
}
200+
sign publishing.publications.maven
201+
}
202+
}

build.gradle

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,39 @@ buildscript {
22
repositories {
33
google()
44
mavenCentral()
5-
jcenter() // @FIXME
65
}
76
dependencies {
87
classpath 'com.android.tools.build:gradle:4.1.3'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
10-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
8+
}
9+
}
10+
11+
plugins {
12+
// must be applied to root project
13+
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0'
14+
}
15+
16+
// These are specific to PdCode, but nexusPublishing needs them here:
17+
// https://github.com/gradle-nexus/publish-plugin/issues/84
18+
group = 'io.github.libpd.android'
19+
version = '1.2.1-SNAPSHOT'
20+
21+
// Create a Sonatype user token for these environment variables:
22+
// export ORG_GRADLE_PROJECT_sonatypeUsername="<tokenUsername>"
23+
// export ORG_GRADLE_PROJECT_sonatypePassword="<tokenPassword>"
24+
nexusPublishing {
25+
repositories {
26+
sonatype {
27+
nexusUrl.set(uri('https://s01.oss.sonatype.org/service/local/'))
28+
snapshotRepositoryUrl.set(uri('https://s01.oss.sonatype.org/content/repositories/snapshots/'))
29+
}
1130
}
1231
}
1332

1433
allprojects {
1534
repositories {
1635
google()
1736
mavenCentral()
18-
jcenter() // @FIXME
37+
jcenter() // FIXME: com.noisepages.nettoyeur:midi
1938
}
2039
}
2140

0 commit comments

Comments
 (0)