Skip to content

Commit

Permalink
Finalize scripts to publish to Maven Central.
Browse files Browse the repository at this point in the history
  • Loading branch information
plecesne committed May 19, 2023
1 parent 7c52467 commit 0fce058
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
/captures
.externalNativeBuild
.cxx
/gpg
local.properties
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.library' version '8.0.1' apply false
}
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
}

apply from: "${rootDir}/crashy/publish-root.gradle"
3 changes: 2 additions & 1 deletion crashy/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
/gpg
24 changes: 12 additions & 12 deletions crashy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '33.0.0'
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier = 'sources'
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
dependencies {
}

task javadocsJar(type: Jar, dependsOn: javadoc){
archiveClassifier = 'javadoc'
from javadoc.destinationDir
ext {
PUBLISH_GROUP_ID = 'io.github.plecesne'
PUBLISH_VERSION = '1.0.0'
PUBLISH_ARTIFACT_ID = 'crashy'
}

dependencies {
}
apply from: "${rootProject.projectDir}/crashy/publish-module.gradle"
73 changes: 73 additions & 0 deletions crashy/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

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

groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

pom {
name = 'CrashyMcCrashFace'
description = 'A library that crashes. A lot.'
url = 'https://github.com/plecesne/crashy'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'plecesne'
name = 'Pierre Lecesne'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:github.com/plecesne/crashy.git'
developerConnection = 'scm:git:ssh://github.com/plecesne/crashy.git'
url = 'https://github.com/plecesne/crashy/tree/main'
}
}
}
}
}
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]

signing {
sign publishing.publications
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
}

task javadocsJar(type: Jar, dependsOn: javadoc){
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocsJar, sourcesJar
}

signing {
sign configurations.archives
}
36 changes: 36 additions & 0 deletions crashy/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Create variables with empty default values
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
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')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

0 comments on commit 0fce058

Please sign in to comment.