Skip to content

Commit

Permalink
Merge pull request #216 from rm3l/publish_libraries_to_maven_central
Browse files Browse the repository at this point in the history
chore(#213): Publish libraries to Maven Central
  • Loading branch information
rm3l authored Mar 6, 2021
2 parents 0c20e2b + 8477a15 commit fbaa936
Show file tree
Hide file tree
Showing 21 changed files with 520 additions and 662 deletions.
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Bintray](https://img.shields.io/bintray/v/rm3l/maven/org.rm3l:maoni.svg)](https://bintray.com/rm3l/maven/org.rm3l%3Amaoni)
[![Maven Central](https://img.shields.io/maven-central/v/org.rm3l/maoni)](https://search.maven.org/artifact/org.rm3l/maoni)
[![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/rm3l/maoni/blob/master/LICENSE)

[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Maoni-blue.svg?style=flat)](http://android-arsenal.com/details/1/3925)
Expand Down Expand Up @@ -125,12 +125,13 @@ By the way, as a side note, Maoni is a Swahili word for comments or opinions.

## Getting started

Grab via Gradle, by adding this to your `build.gradle`:
This library is published on [Maven Central](https://search.maven.org/artifact/org.rm3l/maoni). So importing it should be straightforward.
Add this to your `build.gradle`:

```gradle
dependencies {
// ...
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
}
```

Expand Down Expand Up @@ -193,7 +194,7 @@ Add this additional line to your `build.gradle`:
```gradle
dependencies {
// ...
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
}
```

Expand Down Expand Up @@ -223,8 +224,8 @@ Add this additional line to your `build.gradle`:
```gradle
dependencies {
// ...
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni-slack:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
implementation 'org.rm3l:maoni-slack:8.4.0@aar'
}
```

Expand Down Expand Up @@ -253,8 +254,8 @@ Add this additional line to your `build.gradle`:

```gradle
dependencies {
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni-github:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
implementation 'org.rm3l:maoni-github:8.4.0@aar'
}
```

Expand Down Expand Up @@ -284,8 +285,8 @@ Add this additional line to your `build.gradle`:

```gradle
dependencies {
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni-jira:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
implementation 'org.rm3l:maoni-jira:8.4.0@aar'
}
```

Expand Down Expand Up @@ -316,8 +317,8 @@ Add this additional line to your `build.gradle`:
```gradle
dependencies {
// ...
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni-doorbell:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
implementation 'org.rm3l:maoni-doorbell:8.4.0@aar'
}
```

Expand Down Expand Up @@ -450,26 +451,30 @@ You just have to include `maoni-common` as a dependency in your project, e.g., w
```gradle
dependencies {
// ...
api 'org.rm3l:maoni-common:8.3.2@aar'
api 'org.rm3l:maoni-common:8.4.0@aar'
}
```
You can write your project in any JVM language of your choice (e.g., [Kotlin](https://kotlinlang.org/), as with [maoni-slack](https://github.com/rm3l/maoni-slack) and [maoni-github](https://github.com/rm3l/maoni-github)), as long as the callback implementation can be called from Maoni.

### Publishing a new release

All releases (Git tags) are published to [Bintray](https://bintray.com/rm3l/maven/org.rm3l%3Amaoni).
All releases (Git tags) are published to [Maven Central](https://search.maven.org/search?q=g:org.rm3l) via [Sonatype](https://oss.sonatype.org/#welcome).

To publish to Bintray, you need to have the appropriate rights.
Additionally, your Bintray credentials are expected to be put on your local machine
in `${HOME}/.droid/maoni.bintray.properties`, which should at least contain
the following properties:
- `user` : the username used for publishing
- `key` : your Bintray API Key, which you can retrieve from your Bintray account
The `.github/workflows/build.yml` Workflow file contains a Job responsible for publishing libraries to Sonatype whenever a new tag is pushed.

Alternatively, this operation may be performed manually.
To do so, you can update or create a `local.properties` (local,**not** under version control) file in this repo with the following properties:
- `signing.keyId` : the GPG Signing Key ID
- `signing.secretKeyRingFile` : the path to the GPG signing key file, to use for signing files uploaded to Maven Central
- `signing.password` : the GPG signing key password
- `ossrhUsername` : the Sonatype Nexus Repository username
- `ossrhPassword` : the Sonatype Nexus Repository user password
- `sonatypeStagingProfileId`: the Staging Repo Profile ID (see Sonatype itself to find that information)

The following command can then be run to publish a new version:

```bash
./gradlew build javadoc generatePomFileForReleasePublication bintrayUpload
./gradlew javadoc publishToSonatype closeAndReleaseStagingRepository
```

## In use in the following apps
Expand Down Expand Up @@ -521,7 +526,7 @@ In no particular order:

The MIT License (MIT)

Copyright (c) 2016-2020 Armel Soro
Copyright (c) 2016-2021 Armel Soro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
37 changes: 35 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final homePath = System.properties['user.home']

buildscript {
ext.maoni_group = 'org.rm3l'
ext.maoni_version = '8.3.2'
ext.maoni_version = '8.4.0'

ext.kotlin_version = '1.4.31'
ext.anko_version = '0.10.8'
Expand All @@ -45,14 +45,19 @@ buildscript {
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${aboutlibraries_version}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
// classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.github.triplet.gradle:play-publisher:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "io.github.gradle-nexus:publish-plugin:1.0.0"
}
}

apply plugin: "io.github.gradle-nexus.publish-plugin"

group = maoni_group
version = maoni_version

allprojects {
repositories {
jcenter()
Expand Down Expand Up @@ -127,3 +132,31 @@ subprojects { project ->
}
}

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is ->
p.load(is)
}
p.each { name, value ->
ext[name] = value
}
} else {
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
}

nexusPublishing {
// packageGroup = "org.rm3l" //defaults to 'project.group'
repositories {
sonatype {
stagingProfileId = project.ext.has('sonatypeStagingProfileId') ? project.ext.sonatypeStagingProfileId : ''
username = project.ext.has('ossrhUsername') ? project.ext.ossrhUsername : ''
password = project.ext.has('ossrhPassword') ? project.ext.ossrhPassword : ''
}
}
}
4 changes: 2 additions & 2 deletions callbacks/maoni-doorbell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Add this to your `build.gradle`:

```gradle
dependencies {
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni-doorbell:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
implementation 'org.rm3l:maoni-doorbell:8.4.0@aar'
}
```

Expand Down
152 changes: 63 additions & 89 deletions callbacks/maoni-doorbell/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* SOFTWARE.
*/
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
//apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'

final VERSION_NAME = maoni_version
final VERSION_CODE = VERSION_NAME.replace('.', '').toInteger()
Expand Down Expand Up @@ -92,105 +92,79 @@ artifacts {
archives generateSourcesJar
}

def pomConfig = {
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
email 'armel@rm3l.org'
}
}
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
}

publishing {
publications {
release(MavenPublication) {
// Define this explicitly if using implementation or api configurations
pom.withXml {
def pomNode = asNode()
pomNode.remove(pomNode.get('packaging'))

pomNode.appendNode('name', POM_NAME)
pomNode.appendNode('description', POM_DESCRIPTION)
pomNode.appendNode('url', POM_URL)
pomNode.appendNode('packaging', POM_PACKAGING)

def dependenciesNode = pomNode.getAt('dependencies')[0] ?: pomNode.appendNode('dependencies')

// Iterate over the implementation dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included.
if (it.name != 'unspecified') {
// The coordinates of the library, being set from variables that
// we'll set up later
groupId maoni_group
artifactId 'maoni-doorbell'
version maoni_version

// Two artifacts, the `aar` (or `jar`) and the sources
if (project.plugins.findPlugin("com.android.library")) {
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
} else {
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}
artifact generateSourcesJar
artifact generateJavadocsJar

// Mostly self-explanatory metadata
pom {
name = 'maoni-doorbell'
description = 'Handler for Maoni that sends user feedback to Doorbell.io'
url = 'https://github.com/rm3l/maoni/tree/master/callbacks/maoni-doorbell'
licenses {
license {
name = 'MIT License'
url = 'https://github.com/rm3l/maoni/blob/master/LICENSE'
}
}
developers {
developer {
id = 'rm3l'
name = 'Armel Soro'
email = 'armel@rm3l.org'
}
// 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:rm3l/maoni.git'
developerConnection = 'scm:git:ssh://github.com/rm3l/maoni.git'
url = 'https://github.com/rm3l/maoni/tree/master/callbacks/maoni-doorbell'
}
// A slightly hacky fix so that your POM will include any transitive dependencies
// that your library builds upon
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
if (it.name.startsWith('maoni-')) {
dependencyNode.appendNode('version', '8.3.2')
dependencyNode.appendNode('packaging', 'aar')
} else {
dependencyNode.appendNode('version', it.version)
}
dependencyNode.appendNode('version', it.version)
}
}

pomNode.children().last() + pomConfig
}
}
}
}

bintray {

//Attempt to read keystore.properties file, if any first
final propsFile = new File("${System.properties['user.home']}/.droid/", "maoni.bintray.properties")

if (propsFile.exists()) {
logger.info("[Bintray] Using properties file located at " + propsFile.absolutePath)
final props = new Properties()
props.load(new FileInputStream(propsFile))
user = props['user']
key = props['key']
} else {
user = ""
key = ""
}

publications = ['release']

publish = true //If version should be auto published after an upload

pkg {
repo = 'maven'
name = 'org.rm3l:maoni-doorbell'
labels = ['maoni', 'android', 'feedback', 'android-lib', 'comments', 'review', 'bug', 'issue']

//noinspection GroovyAssignabilityCheck
version {
name = VERSION_NAME
desc = 'Handler for Maoni that sends feedbacks to Doorbell.io'
released = new Date()
vcsTag = VERSION_NAME
// The repository to publish to, Sonatype/MavenCentral
repositories {
maven {
// This is an arbitrary name, you may also use "mavencentral" or
// any other name that's descriptive for you
name = "sonatype"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username rootProject.ext.has('ossrhUsername') ? rootProject.ext.ossrhUsername : ''
password rootProject.ext.has('ossrhPassword') ? rootProject.ext.ossrhPassword : ''
}
}

publicDownloadNumbers = true

licenses = ['MIT']
vcsUrl = 'https://github.com/rm3l/maoni.git'
websiteUrl = 'https://github.com/rm3l/maoni/tree/8.3.2/callbacks/maoni-doorbell'
issueTrackerUrl = 'https://github.com/rm3l/maoni/issues'

}
configurations = ['archives']
}

signing {
sign publishing.publications
}
2 changes: 1 addition & 1 deletion callbacks/maoni-doorbell/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ POM_NAME=maoni-doorbell
POM_DESCRIPTION=Callback for Maoni to send user feedback to Doorbell.io
POM_ARTIFACT_ID=maoni-doorbell
POM_PACKAGING=aar
POM_URL=https://github.com/rm3l/maoni/tree/8.3.2/callbacks/maoni-doorbell
POM_URL=https://github.com/rm3l/maoni/tree/8.4.0/callbacks/maoni-doorbell
4 changes: 2 additions & 2 deletions callbacks/maoni-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Add this to your `build.gradle`:

```gradle
dependencies {
implementation 'org.rm3l:maoni:8.3.2@aar'
implementation 'org.rm3l:maoni-email:8.3.2@aar'
implementation 'org.rm3l:maoni:8.4.0@aar'
implementation 'org.rm3l:maoni-email:8.4.0@aar'
}
```

Expand Down
Loading

0 comments on commit fbaa936

Please sign in to comment.