1
1
/*
2
- * Copyright 2024 Google LLC
2
+ * Copyright 2025 Google LLC
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
17
17
// buildSrc/src/main/kotlin/PublishingConventionPlugin.kt
18
+ import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
19
+ import com.vanniktech.maven.publish.MavenPublishBaseExtension
18
20
import org.gradle.api.Plugin
19
21
import org.gradle.api.Project
20
- import org.gradle.api.publish.PublishingExtension
21
- import org.gradle.api.publish.maven.MavenPublication
22
22
import org.gradle.kotlin.dsl.*
23
23
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
24
24
import org.gradle.api.tasks.testing.Test
25
25
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
26
- import org.gradle.plugins.signing.SigningExtension
27
- import org.gradle.api.publish.maven.*
28
26
29
27
class PublishingConventionPlugin : Plugin <Project > {
30
28
override fun apply (project : Project ) {
31
29
project.run {
32
-
33
30
applyPlugins()
34
31
configureJacoco()
35
- configurePublishing()
36
- configureSigning()
32
+ configureVanniktechPublishing()
37
33
}
38
34
}
39
35
40
36
private fun Project.applyPlugins () {
41
37
apply (plugin = " com.android.library" )
42
38
apply (plugin = " com.mxalbert.gradle.jacoco-android" )
43
- apply (plugin = " maven-publish" )
44
39
apply (plugin = " org.jetbrains.dokka" )
45
- apply (plugin = " signing " )
40
+ apply (plugin = " com.vanniktech.maven.publish " )
46
41
}
47
42
48
43
private fun Project.configureJacoco () {
49
44
configure<JacocoPluginExtension > {
50
45
toolVersion = " 0.8.7"
51
-
52
46
}
53
47
54
48
tasks.withType<Test >().configureEach {
@@ -59,76 +53,46 @@ class PublishingConventionPlugin : Plugin<Project> {
59
53
}
60
54
}
61
55
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
+ )
79
65
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:[email protected] :googlemaps/android-maps-utils.git" )
89
- developerConnection.set(
" scm:[email protected] :googlemaps/android-maps-utils.git" )
90
- url.set(
" scm:[email protected] :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" )
108
78
}
109
79
}
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:[email protected] :googlemaps/android-maps-utils.git" )
82
+ developerConnection.set(
" scm:[email protected] :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." )
123
89
}
124
90
}
91
+ organization {
92
+ name.set(" Google Inc" )
93
+ url.set(" http://developers.google.com/maps" )
94
+ }
125
95
}
126
96
}
127
97
}
128
-
129
- private fun Project.configureSigning () {
130
- configure<SigningExtension > {
131
- sign(extensions.getByType<PublishingExtension >().publications[" aar" ])
132
- }
133
- }
134
98
}
0 commit comments