11/*
2- * Copyright 2024 Google LLC
2+ * Copyright 2025 Google LLC
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1515 */
1616
1717// buildSrc/src/main/kotlin/PublishingConventionPlugin.kt
18+ import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
19+ import com.vanniktech.maven.publish.MavenPublishBaseExtension
1820import org.gradle.api.Plugin
1921import org.gradle.api.Project
20- import org.gradle.api.publish.PublishingExtension
21- import org.gradle.api.publish.maven.MavenPublication
2222import org.gradle.kotlin.dsl.*
2323import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
2424import org.gradle.api.tasks.testing.Test
2525import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
26- import org.gradle.plugins.signing.SigningExtension
27- import org.gradle.api.publish.maven.*
2826
2927class PublishingConventionPlugin : Plugin <Project > {
3028 override fun apply (project : Project ) {
3129 project.run {
32-
3330 applyPlugins()
3431 configureJacoco()
35- configurePublishing()
36- configureSigning()
32+ configureVanniktechPublishing()
3733 }
3834 }
3935
4036 private fun Project.applyPlugins () {
4137 apply (plugin = " com.android.library" )
4238 apply (plugin = " com.mxalbert.gradle.jacoco-android" )
43- apply (plugin = " maven-publish" )
4439 apply (plugin = " org.jetbrains.dokka" )
45- apply (plugin = " signing " )
40+ apply (plugin = " com.vanniktech.maven.publish " )
4641 }
4742
4843 private fun Project.configureJacoco () {
4944 configure<JacocoPluginExtension > {
5045 toolVersion = " 0.8.7"
51-
5246 }
5347
5448 tasks.withType<Test >().configureEach {
@@ -59,76 +53,46 @@ class PublishingConventionPlugin : Plugin<Project> {
5953 }
6054 }
6155
62- private fun Project.configurePublishing () {
63- extensions.configure< com.android.build.gradle.LibraryExtension > {
64- publishing {
65- singleVariant(" release" ) {
66- withSourcesJar()
67- withJavadocJar()
68- }
69- }
70- }
71- extensions.configure<PublishingExtension > {
72- publications {
73- create<MavenPublication >(" aar" ) {
74- artifactId = if (project.name == " library" ) {
75- " android-maps-utils"
76- } else {
77- null
78- }
56+ private fun Project.configureVanniktechPublishing () {
57+ extensions.configure<MavenPublishBaseExtension > {
58+ configure(
59+ AndroidSingleVariantLibrary (
60+ variant = " release" ,
61+ sourcesJar = true ,
62+ publishJavadocJar = true
63+ )
64+ )
7965
80- afterEvaluate {
81- from(components[" release" ])
82- }
83- pom {
84- name.set(project.name)
85- description.set(" Handy extensions to the Google Maps Android API." )
86- url.set(" https://github.com/googlemaps/android-maps-utils" )
87- scm {
88- connection.set(" scm:git@github.com:googlemaps/android-maps-utils.git" )
89- developerConnection.set(" scm:git@github.com:googlemaps/android-maps-utils.git" )
90- url.set(" scm:git@github.com:googlemaps/android-maps-utils.git" )
91- }
92- licenses {
93- license {
94- name.set(" The Apache Software License, Version 2.0" )
95- url.set(" http://www.apache.org/licenses/LICENSE-2.0.txt" )
96- distribution.set(" repo" )
97- }
98- }
99- organization {
100- name.set(" Google Inc" )
101- url.set(" http://developers.google.com/maps" )
102- }
103- developers {
104- developer {
105- name.set(" Google Inc." )
106- }
107- }
66+ publishToMavenCentral()
67+ signAllPublications()
68+
69+ pom {
70+ name.set(project.name)
71+ description.set(" Handy extensions to the Google Maps Android API." )
72+ url.set(" https://github.com/googlemaps/android-maps-utils" )
73+ licenses {
74+ license {
75+ name.set(" The Apache Software License, Version 2.0" )
76+ url.set(" http://www.apache.org/licenses/LICENSE-2.0.txt" )
77+ distribution.set(" repo" )
10878 }
10979 }
110- }
111- repositories {
112- maven {
113- val releasesRepoUrl =
114- uri(" https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/" )
115- val snapshotsRepoUrl =
116- uri(" https://central.sonatype.com/repository/maven-snapshots/" )
117- url = if (project.version.toString()
118- .endsWith(" SNAPSHOT" )
119- ) snapshotsRepoUrl else releasesRepoUrl
120- credentials {
121- username = project.findProperty(" sonatypeToken" ) as String?
122- password = project.findProperty(" sonatypeTokenPassword" ) as String?
80+ scm {
81+ connection.set(" scm:git@github.com:googlemaps/android-maps-utils.git" )
82+ developerConnection.set(" scm:git@github.com:googlemaps/android-maps-utils.git" )
83+ url.set(" https://github.com/googlemaps/android-maps-utils" )
84+ }
85+ developers {
86+ developer {
87+ id.set(" google" )
88+ name.set(" Google Inc." )
12389 }
12490 }
91+ organization {
92+ name.set(" Google Inc" )
93+ url.set(" http://developers.google.com/maps" )
94+ }
12595 }
12696 }
12797 }
128-
129- private fun Project.configureSigning () {
130- configure<SigningExtension > {
131- sign(extensions.getByType<PublishingExtension >().publications[" aar" ])
132- }
133- }
13498}
0 commit comments