Skip to content

Instantly share code, notes, and snippets.

@autonomousapps
Created August 28, 2020 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autonomousapps/1218981f47185382358eb3c00ca76d70 to your computer and use it in GitHub Desktop.
Save autonomousapps/1218981f47185382358eb3c00ca76d70 to your computer and use it in GitHub Desktop.
Publishing android libraries -- the "all" component
import com.android.build.gradle.LibraryExtension
plugins {
`maven-publish`
}
var sourcesJar: TaskProvider<Jar>? = null
pluginManager.withPlugin("com.android.library") {
// Task for generating the source jar so one can attach the source when debugging in other
// projects. Added to debug publication automatically. The 'android' (LibraryExtension) extension
// will only be available on library or application projects, which is why we gate it with
// pluginManager.withPlugin()
sourcesJar = tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
from(project.extensions.getByType<LibraryExtension>().sourceSets["main"].java.srcDirs)
}
}
afterEvaluate {
publishing {
publications {
create<MavenPublication>(component) {
from(components["all"])
groupId = "com.mylib"
version = "1.0"
sourcesJar?.let {
artifact(it.get())
}
}
}
}
if (project.hasProperty("artifactory_user") && project.hasProperty("artifactory_password")) {
val artifactoryUser = project.property("artifactory_user") as String
val artifactoryPassword = project.property("artifactory_password") as String
val baseUrl = project.property("artifactory_contextUrl")
repositories {
maven {
name = "release"
val releaseUrl = "${baseUrl}/release"
val snapshotUrl = "${baseUrl}/snapshots"
url = uri(if (isSnapshot()) snapshotUrl else releaseUrl)
credentials(PasswordCredentials::class.java) {
username = artifactoryUser
password = artifactoryPassword
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment