Skip to content

Instantly share code, notes, and snippets.

@rohitjakhar
Created October 21, 2024 16:02
Show Gist options
  • Select an option

  • Save rohitjakhar/bd355986c816e8580a688eb3174d3b33 to your computer and use it in GitHub Desktop.

Select an option

Save rohitjakhar/bd355986c816e8580a688eb3174d3b33 to your computer and use it in GitHub Desktop.
apply plugin: 'maven-publish'
apply plugin: 'signing'
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
} else {
from sourceSets.main.java.srcDirs
}
}
artifacts {
archives androidSourcesJar
}
group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
// The coordinates of the library, being set from variables that
// we'll set up later
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION
// Two artifacts, the `aar` (or `jar`) and the sources
if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}
artifact androidSourcesJar
// Mostly self-explanatory metadata
pom {
name = PUBLISH_ARTIFACT_ID
description = PUBLISH_DESCRIPTION
url = PUBLISH_URL
licenses {
license {
name = PUBLISH_LICENSE_NAME
url = PUBLISH_LICENSE_URL
}
}
developers {
developer {
id = PUBLISH_DEVELOPER_ID
name = PUBLISH_DEVELOPER_NAME
email = PUBLISH_DEVELOPER_EMAIL
}
}
// Version control info - if you're using GitHub, follow the
// format as seen here
scm {
connection = PUBLISH_SCM_CONNECTION
developerConnection = PUBLISH_SCM_DEVELOPER_CONNECTION
url = PUBLISH_SCM_URL
}
}
}
}
}
}
if (rootProject.ext.hasProperty("signing.keyId")) {
ext["signing.keyId"] = rootProject.ext["signing.keyId"] ?: ""
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]
} else {
println "signing.keyId not found in project."
}
task printData() {
doLast {
// name = rootProject.ext["signing.keyId"] ?: ""
// name1 = rootProject.ext["signing.password"]
// name2 = rootProject.ext["signing.secretKeyRingFile"]
println "key : ${rootProject.ext["signing.keyId"]}"
println "password : ${rootProject.ext["signing.password"]}"
println "file : ${rootProject.ext["signing.secretKeyRingFile"]}"
}
}
signing {
sign publishing.publications
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment