Created
January 30, 2023 07:49
-
-
Save Divya0319/6240baabe4950ccda195e227c09f454b to your computer and use it in GitHub Desktop.
Gradle config files for publishing to MavenCentral. Full article https://proandroiddev.com/publishing-android-libraries-to-mavencentral-in-2021-8ac9975c3e52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lines to add in module level build.gradle file for modules you publish | |
ext { | |
// Provide your own coordinates here | |
PUBLISH_GROUP_ID = 'io.github.divya0319' | |
PUBLISH_VERSION = '1.2.3' | |
PUBLISH_ARTIFACT_ID = 'Watermarking Bitmap in Android' | |
} | |
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lines to add to the project level (root) build.gradle file | |
// 1a: plugins block application of the publishing plugin | |
plugins { | |
id("io.github.gradle-nexus.publish-plugin") version "1.1.0" | |
} | |
// 1b: old plugin syntax for publishing plugin | |
buildscript { | |
dependencies { | |
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' | |
} | |
} | |
apply plugin: 'io.github.gradle-nexus.publish-plugin' | |
// 2: applying separate publishing script | |
apply from: "${rootDir}/scripts/publish-root.gradle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'maven-publish' | |
apply plugin: 'signing' | |
task androidSourcesJar(type: Jar) { | |
archiveClassifier.set('sources') | |
if (project.plugins.findPlugin("com.android.library")) { | |
// For Android libraries | |
from android.sourceSets.main.java.srcDirs | |
// from android.sourceSets.main.kotlin.srcDirs | |
} else { | |
// For pure Kotlin libraries, in case you have them | |
from sourceSets.main.java.srcDirs | |
// from sourceSets.main.kotlin.srcDirs | |
} | |
} | |
task releaseJavadoc(type: Javadoc) { | |
source = android.sourceSets.main.java.srcDirs | |
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) | |
android.libraryVariants.all { variant -> | |
if (variant.name == 'release') { | |
owner.classpath += variant.javaCompileProvider.get().classpath | |
} | |
} | |
exclude '**/R.html', '**/R.*.html', '**/index.html' | |
} | |
task packageJavadoc(type: Jar, dependsOn: 'releaseJavadoc') { | |
archiveClassifier.set("javadoc") | |
from { | |
releaseJavadoc.destinationDir | |
} | |
} | |
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 { | |
from components.java | |
} | |
artifact androidSourcesJar | |
artifact packageJavadoc | |
// Mostly self-explanatory metadata | |
pom { | |
name = PUBLISH_ARTIFACT_ID | |
description = 'Watermark Bitmap in Android' | |
url = 'https://github.com/Divya0319/BmpWatermark' | |
licenses { | |
license { | |
name = 'BmpWatermark License' | |
url = 'https://github.com/Divya0319/BmpWatermark/blob/master/LICENSE' | |
} | |
} | |
developers { | |
developer { | |
id = 'divya0319' | |
name = 'Divya Gupta' | |
email = '[email protected]' | |
} | |
// Add all other devs here... | |
} | |
// Version control info - if you're using GitHub, follow the | |
// format as seen here | |
scm { | |
connection = 'scm:git:github.com/Divya0319/BmpWatermark.git' | |
developerConnection = 'scm:git:ssh://github.com/Divya0319/BmpWatermark.git' | |
url = 'https://github.com/Divya0319/BmpWatermark/tree/master' | |
} | |
} | |
} | |
} | |
} | |
} | |
signing { | |
useInMemoryPgpKeys( | |
rootProject.ext["signing.keyId"], | |
rootProject.ext["signing.key"], | |
rootProject.ext["signing.password"], | |
) | |
sign publishing.publications | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create variables with empty default values | |
ext["ossrhUsername"] = '' | |
ext["ossrhPassword"] = '' | |
ext["sonatypeStagingProfileId"] = '' | |
ext["signing.keyId"] = '' | |
ext["signing.password"] = '' | |
ext["signing.key"] = '' | |
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.key"] = System.getenv('SIGNING_KEY') | |
} | |
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/")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment