Skip to content

Commit f9a30e0

Browse files
authored
[4.x] Build: switch publication to the central portal (#6629)
* switch to the central portal * fix previews
1 parent 46fc3a2 commit f9a30e0

File tree

10 files changed

+70
-132
lines changed

10 files changed

+70
-132
lines changed

.github/workflows/preview.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ jobs:
2727
- run: |
2828
git clone --depth 1 --single-branch --branch ${{ inputs.branch }} https://github.com/$GITHUB_REPOSITORY
2929
cd apollo-kotlin
30-
sed -i .old 's/VERSION_NAME=\([\.0-9]*\).*/VERSION_NAME=\1-${{ inputs.prerelease }}/g' gradle.properties
31-
export GOOGLE_APPLICATION_CREDENTIALS=google-services.json
32-
echo ${GOOGLE_SERVICES_JSON} > $GOOGLE_APPLICATION_CREDENTIALS
33-
./gradlew publishAllPublicationsToApolloPreviewsRepository
30+
LIBRARIAN_NIGHTLY=true ./gradlew librarianPublishToGcs
3431
env:
35-
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
36-
GITHUB_TOKEN: ${{ github.token }}
32+
LIBRARIAN_GOOGLE_SERVICES_JSON: ${{ secrets.APOLLO_KOTLIN_GOOGLE_SERVICES_JSON }}

.github/workflows/push.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ jobs:
2323
with:
2424
gradle-home-cache-cleanup: true
2525
- name: Build with Gradle
26-
#--no-configuration-cache for https://youtrack.jetbrains.com/issue/KT-65879
2726
run: |
28-
./gradlew -p tests ciBuild -i
29-
./gradlew :apollo-kdoc:dokkaGeneratePublicationHtml --no-build-cache
30-
./gradlew ciPublishSnapshot --no-configuration-cache
27+
./gradlew :apollo-kdoc:dokkaGeneratePublicationHtml
28+
./gradlew nmcpPublishAggregationToCentralPortalSnapshots
3129
env:
32-
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
33-
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
34-
COM_APOLLOGRAPHQL_PROFILE_ID: ${{ secrets.COM_APOLLOGRAPHQL_PROFILE_ID }}
30+
LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
31+
LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
3532
- name: Collect Diagnostics
3633
if: always()
3734
run: ./scripts/collect-diagnostics.main.kts

.github/workflows/tag.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ jobs:
2424
#--no-configuration-cache for https://youtrack.jetbrains.com/issue/KT-65879
2525
- name: Publish to Maven Central
2626
run: |
27-
./gradlew --no-build-cache ciPublishRelease -Pgradle.publish.key="${{ secrets.GRADLE_PUBLISH_KEY }}" -Pgradle.publish.secret="${{ secrets.GRADLE_PUBLISH_SECRET }}" --no-configuration-cache
27+
LIBRARIAN_RELEASE=true ./gradlew nmcpPublishAggregationToCentralPortal :apollo-gradle-plugin:publishPlugins -Pgradle.publish.key="${{ secrets.GRADLE_PUBLISH_KEY }}" -Pgradle.publish.secret="${{ secrets.GRADLE_PUBLISH_SECRET }}"
2828
env:
29-
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
30-
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
31-
COM_APOLLOGRAPHQL_PROFILE_ID: ${{ secrets.COM_APOLLOGRAPHQL_PROFILE_ID }}
32-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
33-
GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.GPG_PRIVATE_KEY_PASSWORD }}
29+
LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
30+
LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
31+
GPG_PRIVATE_KEY: ${{ secrets.SONATYPE_GPG_KEY }}
32+
GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.SONATYPE_GPG_KEY_PASSWORD }}

build-logic/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ dependencies {
3030
// See https://github.com/gradle/gradle/issues/4741
3131
implementation(libs.android.plugin)
3232
implementation(libs.gradle.japicmp.plugin)
33-
implementation(libs.vespene)
33+
implementation(libs.librarian)
34+
implementation(libs.nmcp)
3435
implementation(libs.kotlinx.serialization.json)
3536
implementation(libs.poet.java)
3637
implementation(libs.poet.kotlin)

build-logic/src/main/kotlin/Android.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fun Project.configureAndroid(
1111
plugins.apply("com.android.library")
1212

1313
extensions.findByName("android")?.apply {
14-
this as CommonExtension<*, *, *, *, *>
14+
this as CommonExtension<*, *, *, *, *, *>
1515

1616
compileSdk = getCatalogVersion("android.sdkversion.compile").toInt()
1717
this.namespace = namespace

build-logic/src/main/kotlin/Publishing.kt

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import com.android.build.api.dsl.LibraryExtension
22
import com.android.build.gradle.BaseExtension
3-
import kotlinx.coroutines.runBlocking
4-
import net.mbonnin.vespene.lib.NexusStagingClient
53
import org.gradle.api.Project
64
import org.gradle.api.attributes.Usage
75
import org.gradle.api.internal.file.FileOperations
8-
import org.gradle.api.plugins.ExtraPropertiesExtension
96
import org.gradle.api.plugins.JavaPluginExtension
107
import org.gradle.api.publish.PublishingExtension
118
import org.gradle.api.publish.maven.MavenPublication
@@ -44,7 +41,7 @@ fun Project.configurePublishing(isAggregateKdoc: Boolean = false) {
4441
if (isAggregateKdoc) {
4542
configureDokkaAggregate()
4643
}
47-
configurePublishingInternal()
44+
configureModulePublishingInternal()
4845
}
4946

5047
fun Project.configureDokkaCommon(): DokkaExtension {
@@ -97,6 +94,7 @@ fun Project.configureDokka() {
9794

9895
private class MavenCoordinates(val module: String, val version: String)
9996

97+
10098
fun Project.configureDokkaAggregate() {
10199
val dokka = configureDokkaCommon()
102100

@@ -114,7 +112,11 @@ fun Project.configureDokkaAggregate() {
114112
)
115113

116114

117-
val olderVersionsCoordinates = listOf(MavenCoordinates("com.apollographql.apollo3:apollo-kdoc", "3.8.2"))
115+
val olderVersionsCoordinates = listOf(
116+
MavenCoordinates("com.apollographql.apollo:apollo-kdoc", "4.2.0"),
117+
MavenCoordinates("com.apollographql.apollo3:apollo-kdoc", "3.8.2"),
118+
)
119+
118120
val kdocVersionTasks = olderVersionsCoordinates.map { coordinate ->
119121
val versionString = coordinate.version.replace(".", "_").replace("-", "_")
120122
val configuration = configurations.create("apolloKdocVersion_$versionString") {
@@ -149,7 +151,7 @@ fun Project.configureDokkaAggregate() {
149151

150152
dokka.pluginsConfiguration.getByName("versioning") {
151153
this as DokkaVersioningPluginParameters
152-
val currentVersion = findProperty("VERSION_NAME") as String
154+
val currentVersion = version()
153155
version.set(currentVersion)
154156
olderVersionsDir.fileProvider(downloadKDocVersions.map { it.outputs.files.singleFile })
155157
}
@@ -166,33 +168,7 @@ fun Project.configureDokkaAggregate() {
166168

167169
private abstract class FileOperationsHolder @Inject constructor(val fileOperations: FileOperations)
168170

169-
private fun Project.getOssStagingUrl(): String {
170-
val url = try {
171-
this.extensions.extraProperties["ossStagingUrl"] as String?
172-
} catch (e: ExtraPropertiesExtension.UnknownPropertyException) {
173-
null
174-
}
175-
if (url != null) {
176-
return url
177-
}
178-
val baseUrl = "https://s01.oss.sonatype.org/service/local/"
179-
val client = NexusStagingClient(
180-
baseUrl = baseUrl,
181-
username = System.getenv("SONATYPE_NEXUS_USERNAME"),
182-
password = System.getenv("SONATYPE_NEXUS_PASSWORD"),
183-
)
184-
val repositoryId = runBlocking {
185-
client.createRepository(
186-
profileId = System.getenv("COM_APOLLOGRAPHQL_PROFILE_ID"),
187-
description = "apollo-kotlin $version"
188-
)
189-
}
190-
return "${baseUrl}staging/deployByRepositoryId/${repositoryId}/".also {
191-
this.extensions.extraProperties["ossStagingUrl"] = it
192-
}
193-
}
194-
195-
private fun Project.configurePublishingInternal() {
171+
private fun Project.configureModulePublishingInternal() {
196172
val emptyJavadocJar = tasks.register("emptyJavadocJar", org.gradle.jvm.tasks.Jar::class.java) {
197173
archiveClassifier.set("javadoc")
198174

@@ -211,15 +187,6 @@ private fun Project.configurePublishingInternal() {
211187
}
212188
}
213189

214-
tasks.withType(Jar::class.java) {
215-
manifest {
216-
attributes["Built-By"] = findProperty("POM_DEVELOPER_ID") as String?
217-
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
218-
attributes["Implementation-Title"] = findProperty("POM_NAME") as String?
219-
attributes["Implementation-Version"] = findProperty("VERSION_NAME") as String?
220-
}
221-
}
222-
223190
extensions.configure(PublishingExtension::class.java) {
224191
publications {
225192
when {
@@ -326,34 +293,11 @@ private fun Project.configurePublishingInternal() {
326293
name = "pluginTest"
327294
url = uri(rootProject.layout.buildDirectory.dir("localMaven"))
328295
}
329-
330-
maven {
331-
name = "ossSnapshots"
332-
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
333-
credentials {
334-
username = System.getenv("SONATYPE_NEXUS_USERNAME")
335-
password = System.getenv("SONATYPE_NEXUS_PASSWORD")
336-
}
337-
}
338-
339-
maven {
340-
name = "ossStaging"
341-
setUrl {
342-
uri(rootProject.getOssStagingUrl())
343-
}
344-
credentials {
345-
username = System.getenv("SONATYPE_NEXUS_USERNAME")
346-
password = System.getenv("SONATYPE_NEXUS_PASSWORD")
347-
}
348-
}
349-
350-
maven {
351-
name = "apolloPreviews"
352-
setUrl("gcs://apollo-previews/m2")
353-
}
354296
}
355297
}
356298

299+
pluginManager.apply("com.gradleup.nmcp")
300+
357301
// See https://youtrack.jetbrains.com/issue/KT-46466/Kotlin-MPP-publishing-Gradle-7-disables-optimizations-because-of-task-dependencies#focus=Comments-27-7102038.0-0
358302
val signingTasks = tasks.withType(Sign::class.java)
359303
tasks.withType(AbstractPublishToMaven::class.java).configureEach {
@@ -371,7 +315,7 @@ private fun Project.configurePublishingInternal() {
371315
isEnabled = !System.getenv("GPG_PRIVATE_KEY").isNullOrBlank()
372316
}
373317

374-
// https://github.com/gradle/gradle/issues/26132
318+
// https://github.com/gradle/gradle/issues/26091
375319
afterEvaluate {
376320
tasks.all {
377321
if (name.startsWith("compileTestKotlin")) {
@@ -395,7 +339,7 @@ private fun Project.configurePublishingInternal() {
395339
*/
396340
private fun Project.setDefaultPomFields(mavenPublication: MavenPublication) {
397341
mavenPublication.groupId = findProperty("GROUP") as String?
398-
mavenPublication.version = findProperty("VERSION_NAME") as String?
342+
mavenPublication.version = version()
399343

400344
mavenPublication.pom {
401345
name.set(findProperty("POM_NAME") as String?)

build-logic/src/main/kotlin/api.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import app.cash.licensee.LicenseeExtension
22
import app.cash.licensee.UnusedAction
3+
import com.gradleup.librarian.gradle.Librarian
4+
import nmcp.NmcpAggregationExtension
35
import org.gradle.api.Project
46
import org.gradle.api.Task
57
import org.gradle.api.tasks.TaskProvider
68
import org.gradle.jvm.tasks.Jar
79
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
810
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
11+
import kotlin.time.Duration.Companion.hours
12+
import kotlin.time.Duration.Companion.minutes
13+
import kotlin.time.toJavaDuration
914

1015
class AndroidOptions(
1116
val withCompose: Boolean,
@@ -15,6 +20,10 @@ class KotlinCompilerOptions(
1520
val version: KotlinVersion = KotlinVersion.KOTLIN_2_0,
1621
)
1722

23+
fun Project.version(): String {
24+
return Librarian.version(property("VERSION_NAME")!!.toString())
25+
}
26+
1827
fun Project.apolloLibrary(
1928
namespace: String,
2029
jvmTarget: Int? = null,
@@ -28,7 +37,7 @@ fun Project.apolloLibrary(
2837
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
2938
) {
3039
group = property("GROUP")!!
31-
version = property("VERSION_NAME")!!
40+
version = version()
3241

3342
if (androidOptions != null) {
3443
configureAndroid(namespace, androidOptions)
@@ -131,5 +140,28 @@ fun Project.apolloTest(
131140
fun Project.apolloRoot(ciBuild: TaskProvider<Task>) {
132141
configureNode()
133142
rootSetup(ciBuild)
143+
144+
pluginManager.apply("com.gradleup.nmcp.aggregation")
145+
val nmcpAggregation = extensions.getByType(NmcpAggregationExtension::class.java)
146+
nmcpAggregation.apply {
147+
centralPortal {
148+
username.set(System.getenv("LIBRARIAN_SONATYPE_USERNAME"))
149+
password.set(System.getenv("LIBRARIAN_SONATYPE_PASSWORD"))
150+
validationTimeout.set(30.minutes.toJavaDuration())
151+
publishingTimeout.set(1.hours.toJavaDuration())
152+
}
153+
}
154+
155+
Librarian.registerGcsTask(
156+
this,
157+
provider { "apollo-previews" },
158+
provider { "m2" },
159+
provider { System.getenv("LIBRARIAN_GOOGLE_SERVICES_JSON") },
160+
nmcpAggregation.allFiles
161+
)
162+
163+
subprojects.forEach {
164+
configurations.getByName("nmcpAggregation").dependencies.add(dependencies.create(it))
165+
}
134166
}
135167

build.gradle.kts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,6 @@ fun subprojectTasks(name: String): List<Task> {
1717
}
1818
}
1919

20-
fun isTag(): Boolean {
21-
val ref = System.getenv("GITHUB_REF")
22-
23-
return ref?.startsWith("refs/tags/") == true
24-
}
25-
26-
fun shouldPublishSnapshots(): Boolean {
27-
val eventName = System.getenv("GITHUB_EVENT_NAME")
28-
val ref = System.getenv("GITHUB_REF")
29-
30-
return eventName == "push" && (ref == "refs/heads/main")
31-
}
32-
33-
tasks.register("ciPublishSnapshot") {
34-
description = "Publishes a SNAPSHOT"
35-
36-
if (shouldPublishSnapshots()) {
37-
dependsOn(subprojectTasks("publishAllPublicationsToOssSnapshotsRepository"))
38-
} else {
39-
doFirst {
40-
error("We are not on a branch, fail snapshots publishing")
41-
}
42-
}
43-
}
44-
45-
tasks.register("ciPublishRelease") {
46-
description = "Publishes all artifacts to OSSRH and the Gradle Plugin Portal"
47-
48-
if (isTag()) {
49-
dependsOn(subprojectTasks("publishAllPublicationsToOssStagingRepository"))
50-
// Only publish plugins to the Gradle portal if everything else succeeded
51-
finalizedBy(":apollo-gradle-plugin:publishPlugins")
52-
} else {
53-
doFirst {
54-
error("We are not on a tag, fail release publishing")
55-
}
56-
}
57-
58-
}
5920

6021
tasks.register("ciTestsGradle") {
6122
description = "Execute the Gradle tests (slow)"

gradle/libraries.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# The version we use by default in tests and benchmarks
33
# Can be as high as IJ supports
44
# Consult https://kotlinlang.org/docs/multiplatform-compatibility-guide.html#version-compatibility for compatibility with KGP
5-
android-plugin = "8.2.2"
5+
android-plugin = "8.7.2"
66
# The version we compile against
77
android-plugin-min = "8.0.0"
88
# The version used by the 'android-plugin-max' test
@@ -184,7 +184,8 @@ androidx-test-runner = "androidx.test:runner:1.6.2"
184184
truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }
185185
turbine = { group = "app.cash.turbine", name = "turbine", version = "1.1.0" }
186186
uuid = { group = "com.benasher44", name = "uuid", version = "0.8.2" }
187-
vespene = { group = "net.mbonnin.vespene", name = "vespene-lib", version = "0.5" }
187+
librarian = "com.gradleup.librarian:librarian-gradle-plugin:0.0.10-SNAPSHOT-ffba1a28eef796c5c91a33f609761618b0ef2e5e"
188+
nmcp = "com.gradleup.nmcp:nmcp:1.0.1"
188189
slf4j-simple = "org.slf4j:slf4j-simple:2.0.13"
189190
slf4j-nop = "org.slf4j:slf4j-nop:2.0.13"
190191
licensee = "app.cash.licensee:licensee-gradle-plugin:1.12.0"

gradle/repositories.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ listOf(pluginManagement.repositories, dependencyResolutionManagement.repositorie
4242
includeModule("com.gradle", "develocity-gradle-plugin")
4343
}
4444
}
45+
46+
exclusiveContent {
47+
forRepository { maven("https://storage.googleapis.com/gradleup/m2") }
48+
filter {
49+
includeGroup("com.gradleup.librarian")
50+
}
51+
}
4552
}
4653
}

0 commit comments

Comments
 (0)