Created
December 16, 2019 05:03
-
-
Save SaintPatrck/c79afe7d7d30669044e5539a75c88ac6 to your computer and use it in GitHub Desktop.
Publish Android Library to GitHub Packages
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
plugins { | |
id("maven-publish") | |
id("org.jetbrains.dokka") | |
} | |
val versionMajor = 0 | |
val versionMinor = 0 | |
val versionPatch = 1 | |
val artifactVersionCode = versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 | |
val artifactVersionName = "$versionMajor.$versionMinor.$versionPatch" | |
val artifactId = project.name // use `project.name` to match the module name or customize it. | |
val artifactGroupId = "<INSERT_GROUP_ID_HERE>" | |
val artifactPath = "$buildDir/outputs/aar/$artifactId-release.aar" // replace `$artifactId` with the module name if `project.name` is not used. | |
android { | |
// omitted for brevity | |
} | |
dependencies { | |
// omitted for brevity | |
} | |
// Generates dokka javadoc in html format. | |
val dokka by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class) { | |
outputFormat = "html" | |
outputDirectory = "$buildDir/dokka" | |
} | |
// Archives any dokka documentation generated by `dokka` task. | |
val dokkaJar by tasks.creating(Jar::class) { | |
group = JavaBasePlugin.DOCUMENTATION_GROUP | |
description = "Assembles Kotlin docs with Dokka" | |
archiveClassifier.set("javadoc") | |
from(dokka) | |
dependsOn(dokka) | |
} | |
publishing { | |
val gprBaseUrl = "https://maven.pkg.github.com" | |
val gprRepoOwner = <INSERT_GITHUB_REPOSITORY_OWNER> | |
val gprRepoId = <INSERT_GITHUB_REPOSITORY_ID> | |
fun getGrpUser(): String { | |
return if (project.hasProperty("gpr.user")) { | |
project.properties["gpr.user"] as String | |
} else { | |
System.getenv("GPR_USER") ?: "" | |
} | |
} | |
fun getGprKey(): String { | |
return if (project.hasProperty("gpr.key")) { | |
project.properties["gpr.key"] as String | |
} else { | |
System.getenv("GPR_API_KEY") ?: "" | |
} | |
} | |
repositories { | |
maven { | |
name = "GitHubPackages" | |
url = uri("$gprBaseUrl/$gprRepoOwner/$gprRepoId") | |
credentials { | |
username = getGrpUser() | |
password = getGprKey() | |
} | |
} | |
} | |
publications { | |
register("gprRelease", MavenPublication::class) { | |
groupId = artifactGroupId | |
this.artifactId = artifactId | |
version = artifactVersionName | |
artifact(releaseArtifactPath) | |
// include dokka archive in published artifacts | |
artifact(tasks.getByName("dokkaJar")) | |
pom { | |
withXml { | |
// add dependencies to pom | |
val dependencies = asNode().appendNode("dependencies") | |
configurations.implementation.get().dependencies.forEach { | |
if (it.group != null && "unspecified" != it.name && it.version != null) { | |
val dependencyNode = dependencies.appendNode("dependency") | |
dependencyNode.appendNode("groupId", it.group) | |
dependencyNode.appendNode("artifactId", it.name) | |
dependencyNode.appendNode("version", it.version) | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment