|
| 1 | +// buildSrc/src/main/kotlin/PublishingConventionPlugin.kt |
| 2 | +import org.gradle.api.Plugin |
| 3 | +import org.gradle.api.Project |
| 4 | +import org.gradle.api.publish.PublishingExtension |
| 5 | +import org.gradle.api.publish.maven.MavenPublication |
| 6 | +import org.gradle.kotlin.dsl.* |
| 7 | +import org.gradle.testing.jacoco.plugins.JacocoPluginExtension |
| 8 | +import org.gradle.api.tasks.testing.Test |
| 9 | +import org.gradle.testing.jacoco.plugins.JacocoTaskExtension |
| 10 | +import org.gradle.plugins.signing.SigningExtension |
| 11 | +import org.gradle.api.publish.maven.* |
| 12 | + |
| 13 | +class PublishingConventionPlugin : Plugin<Project> { |
| 14 | + override fun apply(project: Project) { |
| 15 | + project.run { |
| 16 | + |
| 17 | + applyPlugins() |
| 18 | + configureJacoco() |
| 19 | + configurePublishing() |
| 20 | + configureSigning() |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + private fun Project.applyPlugins() { |
| 25 | + apply(plugin = "com.android.library") |
| 26 | + apply(plugin = "com.mxalbert.gradle.jacoco-android") |
| 27 | + apply(plugin = "maven-publish") |
| 28 | + apply(plugin = "org.jetbrains.dokka") |
| 29 | + apply(plugin = "signing") |
| 30 | + } |
| 31 | + |
| 32 | + private fun Project.configureJacoco() { |
| 33 | + configure<JacocoPluginExtension> { |
| 34 | + toolVersion = "0.8.7" |
| 35 | + |
| 36 | + } |
| 37 | + |
| 38 | + tasks.withType<Test>().configureEach { |
| 39 | + extensions.configure(JacocoTaskExtension::class.java) { |
| 40 | + isIncludeNoLocationClasses = true |
| 41 | + excludes = listOf("jdk.internal.*") |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + private fun Project.configurePublishing() { |
| 47 | + extensions.configure<com.android.build.gradle.LibraryExtension> { |
| 48 | + publishing { |
| 49 | + singleVariant("release") { |
| 50 | + withSourcesJar() |
| 51 | + withJavadocJar() |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + extensions.configure<PublishingExtension> { |
| 56 | + publications { |
| 57 | + create<MavenPublication>("aar") { |
| 58 | + afterEvaluate { |
| 59 | + from(components["release"]) |
| 60 | + } |
| 61 | + pom { |
| 62 | + name.set(project.name) |
| 63 | + description.set("Handy extensions to the Google Maps Android API.") |
| 64 | + url.set("https://github.com/googlemaps/android-maps-utils") |
| 65 | + scm { |
| 66 | + connection.set( "scm:[email protected]:googlemaps/android-maps-utils.git") |
| 67 | + developerConnection.set( "scm:[email protected]:googlemaps/android-maps-utils.git") |
| 68 | + url.set( "scm:[email protected]:googlemaps/android-maps-utils.git") |
| 69 | + } |
| 70 | + licenses { |
| 71 | + license { |
| 72 | + name.set("The Apache Software License, Version 2.0") |
| 73 | + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") |
| 74 | + distribution.set("repo") |
| 75 | + } |
| 76 | + } |
| 77 | + organization { |
| 78 | + name.set("Google Inc") |
| 79 | + url.set("http://developers.google.com/maps") |
| 80 | + } |
| 81 | + developers { |
| 82 | + developer { |
| 83 | + name.set("Google Inc.") |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + repositories { |
| 90 | + maven { |
| 91 | + val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") |
| 92 | + val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/") |
| 93 | + url = if (project.version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl |
| 94 | + credentials { |
| 95 | + username = project.findProperty("sonatypeToken") as String? |
| 96 | + password = project.findProperty("sonatypeTokenPassword") as String? |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + private fun Project.configureSigning() { |
| 104 | + configure<SigningExtension> { |
| 105 | + sign(extensions.getByType<PublishingExtension>().publications["aar"]) |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments