From a57de3f73d9ee555bc535a05fae6bffa74290c87 Mon Sep 17 00:00:00 2001 From: Xavier Gouchet Date: Tue, 30 Mar 2021 08:05:41 +0200 Subject: [PATCH] :green_heart: Update Maven publishing script (second try) --- .gitlab-ci.yml | 18 +-- .../com/datadog/gradle/config/MavenConfig.kt | 125 ++++++------------ dd-sdk-android-coil/build.gradle.kts | 5 +- dd-sdk-android-fresco/build.gradle.kts | 5 +- dd-sdk-android-glide/build.gradle.kts | 5 +- dd-sdk-android-ktx/build.gradle.kts | 5 +- dd-sdk-android-ndk/build.gradle.kts | 5 +- dd-sdk-android-rx/build.gradle.kts | 5 +- dd-sdk-android-sqldelight/build.gradle.kts | 5 +- dd-sdk-android-timber/build.gradle.kts | 5 +- dd-sdk-android/build.gradle.kts | 5 +- 11 files changed, 73 insertions(+), 115 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5659130a44..e57badeb02 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -148,7 +148,7 @@ publish:release: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-coil: tags: [ "runner:main", "size:large" ] @@ -164,7 +164,7 @@ publish:release-coil: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-coil:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-coil:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-fresco: tags: [ "runner:main", "size:large" ] @@ -180,7 +180,7 @@ publish:release-fresco: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-fresco:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-fresco:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-glide: tags: [ "runner:main", "size:large" ] @@ -196,7 +196,7 @@ publish:release-glide: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-glide:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-glide:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-ktx: tags: [ "runner:main", "size:large" ] @@ -212,7 +212,7 @@ publish:release-ktx: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-ktx:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-ktx:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-ndk: tags: [ "runner:main", "size:large" ] @@ -228,7 +228,7 @@ publish:release-ndk: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-ndk:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-ndk:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-rx: tags: [ "runner:main", "size:large" ] @@ -244,7 +244,7 @@ publish:release-rx: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-rx:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-rx:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-sqldelight: tags: [ "runner:main", "size:large" ] @@ -260,7 +260,7 @@ publish:release-sqldelight: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-sqldelight:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-sqldelight:publishReleasePublicationToMavenRepository --stacktrace --no-daemon publish:release-timber: tags: [ "runner:main", "size:large" ] @@ -276,7 +276,7 @@ publish:release-timber: - export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text) - export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text) - git fetch --depth=1 origin master - - ./gradlew :dd-sdk-android-timber:uploadArchives --stacktrace --no-daemon + - ./gradlew :dd-sdk-android-timber:publishReleasePublicationToMavenRepository --stacktrace --no-daemon # SLACK NOTIFICATIONS diff --git a/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt b/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt index f522001bdc..67f2a7d5e6 100644 --- a/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt +++ b/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt @@ -6,109 +6,60 @@ package com.datadog.gradle.config -import org.apache.maven.model.Developer -import org.apache.maven.model.License -import org.apache.maven.model.Model -import org.apache.maven.model.Scm +import java.net.URI import org.gradle.api.Project -import org.gradle.api.plugins.MavenRepositoryHandlerConvention -import org.gradle.api.tasks.Upload -import org.gradle.internal.impldep.org.sonatype.aether.repository.Authentication -import org.gradle.internal.impldep.org.sonatype.aether.repository.RemoteRepository -import org.gradle.jvm.tasks.Jar +import org.gradle.api.artifacts.repositories.PasswordCredentials +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.findByType import org.gradle.plugins.signing.SigningExtension object MavenConfig { const val GROUP_ID = "com.datadoghq" - const val PASSWORD = "ossrhPassword" - const val USER_NAME = "ossrhUsername" + const val PUBLICATION = "release" } -fun Project.mavenConfig() { - - version = AndroidConfig.VERSION.name - group = MavenConfig.GROUP_ID +@Suppress("UnstableApiUsage") +fun Project.publishingConfig() { val projectName = name - // region Artifact Definition - - @Suppress("UnstableApiUsage") - tasks.register("sourcesJar", Jar::class.java) { - @Suppress("DEPRECATION") - classifier = "sources" - archiveClassifier.convention("sources") - from("${projectDir.canonicalPath}/src/main") - } - - // endregion - - // region Upload Configuration - - taskConfig { - repositories { - val mavenHandler = this as? MavenRepositoryHandlerConvention ?: return@repositories - - mavenHandler.mavenDeployer { - beforeDeployment { - @Suppress("DEPRECATION") - this@mavenConfig.extensions.findByType(SigningExtension::class.java) - ?.signPom(this) - } - - repository = RemoteRepository().apply { - url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - // To publish to local URL, uncomment next line - // url = "http://localhost:8081/nexus/service/local/staging/deploy/maven2/" + afterEvaluate { + val publishingExtension = extensions.findByType(PublishingExtension::class) + val signingExtension = extensions.findByType(SigningExtension::class) + if (publishingExtension == null || signingExtension == null) { + System.err.println("Missing publishing or signing extension for $projectName") + return@afterEvaluate + } - val username = System.getenv("OSSRH_USERNAME") - val password = System.getenv("OSSRH_PASSWORD") - if ((!username.isNullOrEmpty()) && (!password.isNullOrEmpty())) { - authentication = Authentication(username, password) + publishingExtension.apply { + repositories.maven { + url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + val username = System.getenv("OSSRH_USERNAME") + val password = System.getenv("OSSRH_PASSWORD") + if ((!username.isNullOrEmpty()) && (!password.isNullOrEmpty())) { + credentials(PasswordCredentials::class.java) { + setUsername(username) + setPassword(password) } + } else { + System.err.println("Missing publishing credentials for $projectName") } + } - pom.groupId = MavenConfig.GROUP_ID - pom.artifactId = projectName - pom.version = AndroidConfig.VERSION.name - pom.project { - check(this is Model) - name = projectName - packaging = "aar" - url = "https://www.datadoghq.com/" - scm = Scm().apply { - url = "https://github.com/DataDog/dd-sdk-android.git" - connection = "scm:git@github.com:DataDog/dd-sdk-android.git" - developerConnection = "scm:git@github.com:DataDog/dd-sdk-android.git" - } - addLicense(License().apply { - name = "The Apache Software License, Version 2.0" - url = "http://www.apache.org/licenses/LICENSE-2.0.txt" - distribution = "repo" - }) - - addDeveloper(Developer().apply { - id = "DataDog" - name = "Datadog, Inc." - }) - } + publications.create(MavenConfig.PUBLICATION, MavenPublication::class.java) { + from(components.getByName("release")) + groupId = MavenConfig.GROUP_ID + artifactId = projectName + version = AndroidConfig.VERSION.name } } - } - afterEvaluate { - artifacts { - add("archives", tasks.findByName("sourcesJar")!!) + signingExtension.apply { + val privateKey = System.getenv("GPG_PRIVATE_KEY") + val password = System.getenv("GPG_PASSWORD") + isRequired = true + useInMemoryPgpKeys(privateKey, password) + sign(publishingExtension.publications.getByName(MavenConfig.PUBLICATION)) } } - - @Suppress("UnstableApiUsage") - extensionConfig { - val privateKey = System.getenv("GPG_PRIVATE_KEY") - val password = System.getenv("GPG_PASSWORD") - isRequired = true - useInMemoryPgpKeys(privateKey, password) - sign(configurations.getByName("archives")) - } - - // endregion } diff --git a/dd-sdk-android-coil/build.gradle.kts b/dd-sdk-android-coil/build.gradle.kts index ce0fa22dc1..d6e33e4b3e 100644 --- a/dd-sdk-android-coil/build.gradle.kts +++ b/dd-sdk-android-coil/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.testImplementation plugins { @@ -24,6 +24,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -95,4 +96,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-fresco/build.gradle.kts b/dd-sdk-android-fresco/build.gradle.kts index 91aed1b4ce..1bb831a3d0 100644 --- a/dd-sdk-android-fresco/build.gradle.kts +++ b/dd-sdk-android-fresco/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.implementation import com.datadog.gradle.testImplementation @@ -24,6 +24,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -95,4 +96,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-glide/build.gradle.kts b/dd-sdk-android-glide/build.gradle.kts index ce29c66f07..08d3a7154b 100644 --- a/dd-sdk-android-glide/build.gradle.kts +++ b/dd-sdk-android-glide/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.implementation import com.datadog.gradle.testImplementation @@ -25,6 +25,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -99,4 +100,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-ktx/build.gradle.kts b/dd-sdk-android-ktx/build.gradle.kts index 44dfb3f3ec..3f63958618 100644 --- a/dd-sdk-android-ktx/build.gradle.kts +++ b/dd-sdk-android-ktx/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.implementation import com.datadog.gradle.testImplementation @@ -24,6 +24,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -97,4 +98,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-ndk/build.gradle.kts b/dd-sdk-android-ndk/build.gradle.kts index d12c489a1b..616ce93836 100644 --- a/dd-sdk-android-ndk/build.gradle.kts +++ b/dd-sdk-android-ndk/build.gradle.kts @@ -14,7 +14,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.testImplementation plugins { @@ -24,6 +24,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -131,4 +132,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-rx/build.gradle.kts b/dd-sdk-android-rx/build.gradle.kts index 2c0bc52b58..f28dfb027b 100644 --- a/dd-sdk-android-rx/build.gradle.kts +++ b/dd-sdk-android-rx/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.testImplementation plugins { @@ -23,6 +23,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -94,4 +95,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-sqldelight/build.gradle.kts b/dd-sdk-android-sqldelight/build.gradle.kts index 84cc695607..096dafbc58 100644 --- a/dd-sdk-android-sqldelight/build.gradle.kts +++ b/dd-sdk-android-sqldelight/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.testImplementation plugins { @@ -23,6 +23,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -94,4 +95,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android-timber/build.gradle.kts b/dd-sdk-android-timber/build.gradle.kts index d42958ccc8..4d5e966db5 100644 --- a/dd-sdk-android-timber/build.gradle.kts +++ b/dd-sdk-android-timber/build.gradle.kts @@ -13,7 +13,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.testImplementation plugins { @@ -23,6 +23,7 @@ plugins { // Publish `maven-publish` + signing id("org.jetbrains.dokka") // Analysis tools @@ -94,4 +95,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig() diff --git a/dd-sdk-android/build.gradle.kts b/dd-sdk-android/build.gradle.kts index bc0a9210e6..de015bfbee 100644 --- a/dd-sdk-android/build.gradle.kts +++ b/dd-sdk-android/build.gradle.kts @@ -16,7 +16,7 @@ import com.datadog.gradle.config.javadocConfig import com.datadog.gradle.config.junitConfig import com.datadog.gradle.config.kotlinConfig import com.datadog.gradle.config.ktLintConfig -import com.datadog.gradle.config.mavenConfig +import com.datadog.gradle.config.publishingConfig import com.datadog.gradle.implementation import com.datadog.gradle.testImplementation @@ -27,7 +27,6 @@ plugins { kotlin("kapt") // Publish - maven `maven-publish` signing id("org.jetbrains.dokka") @@ -179,4 +178,4 @@ junitConfig() jacocoConfig() javadocConfig() dependencyUpdateConfig() -mavenConfig() +publishingConfig()