Forked from wasabeef/0-how-to-use-maven-central-publish.sh
Created
July 7, 2021 04:59
-
-
Save belinwu/dc8cc8d1273b72298cba3d5dc04ed3c4 to your computer and use it in GitHub Desktop.
maven-central-v1.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
./gradlew clean buildRelease publish |
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
// Sample Library | |
apply plugin: 'com.android.library' | |
apply plugin: 'kotlin-android' | |
android { | |
compileSdkVersion COMPILE_SDK_VERSION as int | |
defaultConfig { | |
minSdkVersion MIN_SDK_VERSION as int | |
targetSdkVersion TARGET_SDK_VERSION as int | |
} | |
} | |
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
} | |
ext { | |
publishedGroupId = 'jp.wasabeef' | |
artifact = 'recyclerview-animators' | |
libraryDescription = 'Which provides simple Item animations to RecyclerView items' | |
siteUrl = 'https://github.com/wasabeef/recyclerview-animators' | |
gitUrl = 'https://github.com/wasabeef/recyclerview-animators.git' | |
libraryVersion = VERSION_NAME | |
developerId = 'wasabeef' | |
developerName = 'Wasabeef' | |
developerEmail = '[email protected]' | |
licenseName = 'The Apache Software License, Version 2.0' | |
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | |
} | |
apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.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
# ~/.gradle/gradle.properties | |
## Maven Central | |
signing.keyId=******** | |
signing.password=************** | |
signing.secretKeyRingFile=/Users/wasabeef/.gnupg/secring.gpg | |
sonatypeUsername=******** | |
sonatypePassword=******************************************** |
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' | |
def sonatypeUsername = rootProject.hasProperty('sonatypeUsername')? rootProject.sonatypeUsername : '' | |
def sonatypePassword = rootProject.hasProperty('sonatypePassword')? rootProject.sonatypePassword : '' | |
group = publishedGroupId | |
version = libraryVersion | |
task sourcesJar(type: Jar) { | |
archiveClassifier.set("sources") | |
from android.sourceSets.getByName("main").java.srcDirs | |
} | |
task javadoc(type: Javadoc) { | |
options.addStringOption('Xdoclint:none', '-quiet') | |
source = android.sourceSets.getByName("main").java.srcDirs | |
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) | |
} | |
task javadocJar(type: Jar, dependsOn: javadoc) { | |
archiveClassifier.set("javadoc") | |
from javadoc.destinationDir | |
} | |
afterEvaluate { | |
publishing { | |
publications { | |
release(MavenPublication) { | |
artifactId = artifact | |
from components.release | |
artifact javadocJar | |
artifact sourcesJar | |
pom { | |
name = artifact | |
description = libraryDescription | |
url = siteUrl | |
licenses { | |
license { | |
name = licenseName | |
url = licenseUrl | |
} | |
} | |
developers { | |
developer { | |
id = developerId | |
name = developerName | |
email = developerEmail | |
} | |
} | |
scm { | |
connection = gitUrl | |
developerConnection = gitUrl | |
url = siteUrl | |
} | |
} | |
} | |
} | |
repositories { | |
maven { | |
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" | |
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" | |
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl | |
credentials { | |
username = "${sonatypeUsername}" | |
password = "${sonatypePassword}" | |
} | |
} | |
} | |
} | |
} | |
signing { | |
sign publishing.publications | |
} | |
javadoc { | |
if (JavaVersion.current().isJava9Compatible()) { | |
options.addBooleanOption('html5', true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment