Adjustments for publishing artifacts to Maven Central

This commit is contained in:
Nick Parker 2022-08-03 14:42:26 -05:00
parent 85580ff3c1
commit bc7c96a6de
3 changed files with 72 additions and 38 deletions

View File

@ -11,7 +11,9 @@ build-debug:
$(GRADLE) assembleDebug
build-release:
$(GRADLE) assembleRelease
$(GRADLE) \
-PsqlcipherAndroidVersion="$(SQLCIPHER_ANDROID_VERSION)" \
assembleRelease
publish-snapshot-to-local-maven:
@ $(collect-signing-info) \
@ -22,18 +24,20 @@ publish-snapshot-to-local-maven:
-Psigning.password="$$gpgPassword" \
publishReleasePublicationToMavenLocal
publish-snapshot-to-local-nexus:
publish-remote-release:
@ $(collect-signing-info) \
$(collect-nexus-info) \
$(GRADLE) \
-PpublishSnapshot=true \
-Psigning.keyId="$$gpgKeyId" \
-Psigning.secretKeyRingFile="$$gpgKeyRingFile" \
-Psigning.password="$$gpgPassword" \
-PpublishSnapshot=false \
-PpublishLocal=false \
-PdebugBuild=false \
-PsigningKeyId="$$gpgKeyId" \
-PsigningKeyRingFile="$$gpgKeyRingFile" \
-PsigningKeyPassword="$$gpgPassword" \
-PnexusUsername="$$nexusUsername" \
-PnexusPassword="$$nexusPassword" \
-PnexusStagingProfileId="$$nexusStagingProfileId" \
publishAllPublicationsToLocalNexusRepository
-PsqlcipherAndroidVersion="$(SQLCIPHER_ANDROID_VERSION)" \
sqlcipher:publish
collect-signing-info := \
read -p "Enter GPG signing key id:" gpgKeyId; \
@ -42,6 +46,5 @@ collect-signing-info := \
read -p "Enter GPG password:" gpgPassword; stty echo;
collect-nexus-info := \
read -p "Enter Nexus username:" nexusUsername; stty -echo; \
read -p "Enter Nexus password:" nexusPassword; stty echo; \
read -p "Enter Nexus staging profile id:" nexusStagingProfileId;
read -p "Enter Nexus username:" nexusUsername; \
stty -echo; read -p "Enter Nexus password:" nexusPassword; stty echo;

View File

@ -56,26 +56,6 @@ project.ext {
nexusStagingProfileId = project.hasProperty('nexusStagingProfileId') ? "${nexusStagingProfileId}" : ""
}
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("https://oss.sonatype.org/")
snapshotRepositoryUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
username = "${rootProject.ext.nexusUsername}"
password = "${rootProject.ext.nexusPassword}"
stagingProfileId = "${rootProject.ext.nexusStagingProfileId}"
}
localNexus {
useStaging = false
nexusUrl = uri("http://localhost:8081/")
snapshotRepositoryUrl = uri("http://localhost:8081/repository/maven-snapshots/")
username = "${rootProject.ext.nexusUsername}"
password = "${rootProject.ext.nexusPassword}"
stagingProfileId = ""
}
}
}
task generateReadMe {
def readme = new File("README.md")
def engine = new SimpleTemplateEngine()

View File

@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: "maven-publish"
apply plugin: "signing"
android {
compileSdkVersion 30
@ -74,10 +76,44 @@ allprojects {
}
}
def isReleaseBuild() {
return mavenVersionName.contains("SNAPSHOT") == false
}
def getReleaseRepositoryUrl() {
return hasProperty('mavenReleaseRepositoryUrl') ? mavenReleaseRepositoryUrl
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
if(hasProperty('mavenLocalRepositoryPrefix')) {
return "${mavenLocalRepositoryPrefix}${buildDir}/${mavenSnapshotRepositoryUrl}"
} else {
return hasProperty('mavenSnapshotRepositoryUrl') ? mavenSnapshotRepositoryUrl
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
def getRepositoryUsername() {
return hasProperty('nexusUsername') ? nexusUsername : ""
}
def getRepositoryPassword() {
return hasProperty('nexusPassword') ? nexusPassword : ""
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { it instanceof Sign }) {
allprojects { ext."signing.keyId" = "${signingKeyId}" }
allprojects { ext."signing.secretKeyRingFile" = "${signingKeyRingFile}" }
allprojects { ext."signing.password" = "${signingKeyPassword}" }
}
}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
mavenJava(MavenPublication) {
groupId = "net.zetetic"
artifactId = "sqlcipher-android"
version = "${rootProject.ext.mavenVersionName}"
@ -109,18 +145,33 @@ afterEvaluate {
}
}
}
repositories {
maven {
def repoUrl = isReleaseBuild()
? getReleaseRepositoryUrl()
: getSnapshotRepositoryUrl()
url = repoUrl
credentials {
username = getRepositoryUsername()
password = getRepositoryPassword()
}
}
}
}
signing {
sign publishing.publications
required { isReleaseBuild() && gradle.taskGraph.hasTask("publish") }
sign publishing.publications.mavenJava
}
artifacts {
archives androidSourcesJar
}
}
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
}
}