Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for MavenCentral publishing #779

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.22.0"
}
}

Expand All @@ -22,3 +23,5 @@ allprojects {
ext {
sdkVersion = 29
}

apply plugin: 'io.codearte.nexus-staging'
74 changes: 66 additions & 8 deletions photoview/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

android {
compileSdkVersion rootProject.ext.sdkVersion
Expand All @@ -16,24 +17,62 @@ dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
}

def PUBLISH_GROUP_ID = 'com.github.chrisbanes'
def PUBLISH_ARTIFACT_ID = 'PhotoView'
def PUBLISH_VERSION = '2.3.0'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These coordinates might have to be reconsidered as MavenCentral requires verification for publishing with a given group ID


ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''

File localPropsFile = project.rootProject.file('local.properties')
if (localPropsFile.exists()) {
println "Found local props file, loading props from there"
Properties p = new Properties()
new FileInputStream(localPropsFile).withCloseable { is ->
p.load(is)
}
p.each { name, value ->
ext[name] = value
}
} else {
println "No local props file, loading env vars instead"
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')
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Set to empty values initially, so that they exist, but are empty. This allows people to build the debug variant locally.
  • Use local.properties values if they're there, this can be used for publishing from a local machine.
  • Use environment variables if the local.properties file was missing, can be used on CI.


nexusStaging {
packageGroup = PUBLISH_GROUP_ID
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release

group = 'com.github.chrisbanes'
artifactId = 'PhotoView'
version = '2.3.0'
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

// Adds javadocs and sources as separate jars.
artifact androidJavadocsJar
artifact(sourceJar)

pom {
name = 'PhotoView'
name = PUBLISH_ARTIFACT_ID
description = 'A simple ImageView that support zooming, both by Multi-touch gestures and double-tap.'
url = 'https://github.com/chrisbanes/PhotoView'
url = 'https://github.com/Baseflow/PhotoView'
licenses {
license {
name = 'The Apache License, Version 2.0'
Expand All @@ -47,16 +86,35 @@ afterEvaluate {
}
}
scm {
connection = 'scm:[email protected]/chrisbanes/PhotoView.git'
developerConnection = 'scm:[email protected]/chrisbanes/PhotoView.git'
url = 'https://github.com/chrisbanes/PhotoView'
connection = 'scm:[email protected]/Baseflow/PhotoView.git'
developerConnection = 'scm:[email protected]/Baseflow/PhotoView.git'
url = 'https://github.com/Baseflow/PhotoView'
}
}
}
}

repositories {
maven {
name = "sonatype"

def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

credentials {
username ossrhUsername
password ossrhPassword
}
}
}
}
}

signing {
sign publishing.publications
}

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
Expand Down