Skip to content

Commit 5281381

Browse files
authored
chore: migrating to vanniktech plugin (#1547)
* chore: migrating to vanniktech plugin * chore: removed old properties
1 parent d4efcc3 commit 5281381

File tree

6 files changed

+55
-84
lines changed

6 files changed

+55
-84
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ jobs:
3232
java-version: '17'
3333
distribution: 'temurin'
3434
- uses: gradle/actions/wrapper-validation@v4
35-
- name: Create .gpg key
35+
- name: Set up Gradle Publishing Environment Variables
3636
run: |
3737
echo $GPG_KEY_ARMOR | base64 --decode > ./release.asc
3838
gpg --quiet --output $GITHUB_WORKSPACE/release.gpg --dearmor ./release.asc
3939
4040
echo "Build and publish"
41-
sed -i -e "s,sonatypeToken=,sonatypeToken=$SONATYPE_TOKEN_USERNAME,g" gradle.properties
41+
sed -i -e "s,mavenCentralUsername=,mavenCentralUsername=$SONATYPE_TOKEN_USERNAME,g" gradle.properties
4242
SONATYPE_TOKEN_PASSWORD_ESCAPED=$(printf '%s\n' "$SONATYPE_TOKEN_PASSWORD" | sed -e 's/[\/&]/\\&/g')
43-
sed -i -e "s,sonatypeTokenPassword=,sonatypeTokenPassword=$SONATYPE_TOKEN_PASSWORD_ESCAPED,g" gradle.properties
43+
sed -i -e "s,mavenCentralPassword=,mavenCentralPassword=$SONATYPE_TOKEN_PASSWORD_ESCAPED,g" gradle.properties
4444
sed -i -e "s,signing.keyId=,signing.keyId=$GPG_KEY_ID,g" gradle.properties
4545
sed -i -e "s,signing.password=,signing.password=$GPG_PASSWORD,g" gradle.properties
4646
sed -i -e "s,signing.secretKeyRingFile=,signing.secretKeyRingFile=$GITHUB_WORKSPACE/release.gpg,g" gradle.properties
4747
env:
48-
GPG_KEY_ARMOR: "${{ secrets.SYNCED_GPG_KEY_ARMOR }}"
48+
GPG_KEY_ARMOR: ${{ secrets.SYNCED_GPG_KEY_ARMOR }}
4949
GPG_KEY_ID: ${{ secrets.SYNCED_GPG_KEY_ID }}
5050
GPG_PASSWORD: ${{ secrets.SYNCED_GPG_KEY_PASSWORD }}
5151
SONATYPE_TOKEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }}

.releaserc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins:
2020
to: ":${nextRelease.version}"
2121
- - "@semantic-release/exec"
2222
- prepareCmd: "./gradlew build --warn --stacktrace"
23-
publishCmd: "./gradlew publish --warn --stacktrace --debug --info"
23+
publishCmd: "./gradlew publishToMavenCentral --warn --stacktrace --debug --info"
2424
- - "@semantic-release/git"
2525
- assets:
2626
- "build.gradle.kts"

build-logic/convention/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies {
3030
implementation(libs.gradle)
3131
implementation(libs.dokka.gradle.plugin)
3232
implementation(libs.org.jacoco.core)
33+
implementation(libs.gradle.maven.publish.plugin)
3334
}
3435

3536
gradlePlugin {
Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -15,40 +15,34 @@
1515
*/
1616

1717
// buildSrc/src/main/kotlin/PublishingConventionPlugin.kt
18+
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
19+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
1820
import org.gradle.api.Plugin
1921
import org.gradle.api.Project
20-
import org.gradle.api.publish.PublishingExtension
21-
import org.gradle.api.publish.maven.MavenPublication
2222
import org.gradle.kotlin.dsl.*
2323
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
2424
import org.gradle.api.tasks.testing.Test
2525
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
26-
import org.gradle.plugins.signing.SigningExtension
27-
import org.gradle.api.publish.maven.*
2826

2927
class 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:[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")
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:[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.")
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
}

gradle.properties

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ signing.keyId=
3030
signing.password=
3131
signing.secretKeyRingFile=
3232

33-
sonatypeToken=
34-
sonatypeTokenPassword=
35-
3633
android.defaults.buildfeatures.buildconfig=true
34+
35+
mavenCentralUsername=
36+
mavenCentralPassword=
37+
38+
# Add a property to enable automatic release to Maven Central (optional, but good for CI)
39+
# If true, publishToMavenCentral will also close and release the staging repository
40+
mavenCentralAutomaticRelease=false

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mockk = "1.14.4"
1919
lint = "31.11.0"
2020
org-jacoco-core = "0.8.13"
2121
material = "1.12.0"
22+
gradleMavenPublishPlugin = "0.34.0"
2223

2324
[libraries]
2425
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
@@ -47,4 +48,5 @@ lint = { module = "com.android.tools.lint:lint", version.ref = "lint" }
4748
lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref = "lint" }
4849
testutils = { module = "com.android.tools:testutils", version.ref = "lint" }
4950
org-jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "org-jacoco-core" }
50-
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
51+
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
52+
gradle-maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradleMavenPublishPlugin" }

0 commit comments

Comments
 (0)