Skip to content

Commit

Permalink
android.gradle: add signing and publishing tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 20, 2025
1 parent eb78cb0 commit dba8b82
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ jobs:
run: |
./gradlew classes unpackJoltSource unpackTestFramework \
--console=plain
- name: gradlew --build-file=android.gradle assemble
- name: gradlew --build-file=android.gradle -Partifact=jolt-jni-Android_ARM8 install
run: |
./gradlew --build-file=android.gradle assemble \
./gradlew --build-file=android.gradle -Partifact=jolt-jni-Android_ARM8 install \
--console=plain
Java21-x-Linux_ARM32hf:
Expand Down
106 changes: 106 additions & 0 deletions android.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// Gradle script to build/publish jolt-jni Android artifacts

plugins {
id 'maven-publish' // to publish artifacts to Maven repositories
id 'signing' // to sign artifacts for publication

alias(libs.plugins.android.library) // to build Android libraries
}

// $artifact is set in the gradle.properties file
// or by a -Partifact= option on the command line.

ext {
groupID = 'com.github.stephengold'
jjVersion = '0.9.5-SNAPSHOT'
baseName = "${artifact}-${jjVersion}" // for artifacts
websiteUrl = 'https://github.com/stephengold/jolt-jni'
}

android {
buildTypes {
debug {
Expand Down Expand Up @@ -76,3 +86,99 @@ dependencies {
testImplementation(libs.jsnaploader)
testImplementation(libs.junit4)
}

// Register publishing tasks:

tasks.register('install') {
dependsOn 'publishMavenPublicationToMavenLocal'
description = 'Installs Maven artifacts to the local repository.'
}
tasks.register('release') {
dependsOn 'publishMavenPublicationToOSSRHRepository'
description = 'Stages Maven artifacts to Sonatype OSSRH.'
}

publishing {
publications {
maven(MavenPublication) {
artifactId = artifact
afterEvaluate { from components.default }
groupId = groupID
pom {
description = 'a JNI interface to Jolt Physics'
developers {
developer {
email = '[email protected]'
id = 'stephengold'
name = 'Stephen Gold'
}
}
inceptionYear = '2024'
licenses {
license {
distribution = 'repo'
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
name = groupID + ':' + artifact
scm {
connection = 'scm:git:git://github.com/stephengold/jolt-jni.git'
developerConnection = 'scm:git:ssh://github.com:stephengold/jolt-jni.git'
url = websiteUrl + '/tree/master'
}
url = websiteUrl
}
version = jjVersion
}
}

repositories {
maven { // the staging repo of Sonatype OSSRH

// Staging to OSSRH relies on the existence of 2 properties
// (ossrhUsername and ossrhPassword)
// which should be set in the ~/.gradle/gradle.properties file
// or by -P options on the command line.

credentials {
username = project.hasProperty('ossrhUsername') ? ossrhUsername : 'Unknown user'
password = project.hasProperty('ossrhPassword') ? ossrhPassword : 'Unknown password'
}
name = 'OSSRH'
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2'
}
}
}
publishMavenPublicationToMavenLocal.dependsOn('assemble')
publishMavenPublicationToMavenLocal.doLast {
println 'installed locally as ' + baseName
}

// Register tasks to sign artifacts for publication:

// Signing relies on the existence of 2 properties
// (signingKeyEncoded and signingPassword)
// which should be set in the ~/.gradle/gradle.properties file
// or by -P options on the command line.

signing {
def signingKey = base64Decode(findProperty('signingKeyEncoded'))
def signingPassword = findProperty('signingPassword')
useInMemoryPgpKeys(signingKey, signingPassword)

sign configurations.archives
sign publishing.publications.maven
}
tasks.withType(Sign).configureEach {
onlyIf { project.hasProperty('signingKeyEncoded') }
}

static def base64Decode(encodedString) {
if (encodedString != null) {
byte[] decoded = encodedString.decodeBase64()
String decode = new String(decoded)
return decode
}
return null
}

0 comments on commit dba8b82

Please sign in to comment.