Last active
September 9, 2019 13:42
-
-
Save Nimrodda/4119835a05045a0101db927a39a65f72 to your computer and use it in GitHub Desktop.
Script for publishing Android Kotlin libraries to Maven repository with sources and KDocs included
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
/* | |
* Script for publishing Android Kotlin libraries to Maven repository with sources and KDocs included. | |
* Inspired by: https://github.com/JakeWharton/butterknife/blob/f0b735144d24592d665eeff90051b6adea2e564a/gradle/gradle-mvn-push.gradle | |
* Copy this file to your project's root dir and then apply it to the bottom of build.gradle of the modules you wish | |
* to publish: apply from: '../maven-publish.gradle` | |
* The publish with the following command: | |
* ./gradlew :modulename:uploadArchives | |
* Note that this script doesn't define signing configuration. See link above for example. | |
* This scripts requires the presence of a gradle.properties file in the module's root | |
* with the following properties defined: | |
* POM_ARTIFACT_ID=artifact-name | |
* POM_NAME=artifact description | |
* POM_PACKAGING=aar/jar | |
* VERSION_NAME=1.0.0 | |
* GROUP=group ID/package | |
*/ | |
apply plugin: 'maven' | |
apply plugin: 'org.jetbrains.dokka-android' | |
dokka { | |
outputFormat = 'gfm' | |
} | |
task sourcesJar(type: Jar) { | |
from android.sourceSets.main.java.srcDirs | |
archiveClassifier.set("sources") | |
} | |
task javadocJar(type: Jar, dependsOn: dokka) { | |
archiveClassifier.set("javadoc") | |
from dokka.outputDirectory | |
} | |
artifacts { | |
archives sourcesJar | |
archives javadocJar | |
} | |
ext.repoUrl = "repourl" | |
def getReleaseRepositoryUrl() { | |
return "${repoUrl}/release" | |
} | |
def getSnapshotRepositoryUrl() { | |
return "${repoUrl}/snapshot" | |
} | |
version = VERSION_NAME | |
group = GROUP | |
if (project.hasProperty("artifactory_user")) { | |
uploadArchives { | |
repositories { | |
mavenDeployer { | |
pom.groupId = GROUP | |
pom.artifactId = POM_ARTIFACT_ID | |
pom.version = VERSION_NAME | |
repository(url: getReleaseRepositoryUrl()) { | |
authentication(userName: artifactory_user, password: artifactory_password) | |
} | |
snapshotRepository(url: getSnapshotRepositoryUrl()) { | |
authentication(userName: artifactory_user, password: artifactory_password) | |
} | |
} | |
} | |
} | |
} else { | |
logger.warn("Missing artifactory credentials, you won't be able to publish") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment