Skip to content

Commit

Permalink
💚 Update Maven publishing script (second try)
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Mar 30, 2021
1 parent 9d87900 commit a57de3f
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 115 deletions.
18 changes: 9 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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" ]
Expand All @@ -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

Expand Down
125 changes: 38 additions & 87 deletions buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Upload> {
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:[email protected]:DataDog/dd-sdk-android.git"
developerConnection = "scm:[email protected]: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<SigningExtension> {
val privateKey = System.getenv("GPG_PRIVATE_KEY")
val password = System.getenv("GPG_PASSWORD")
isRequired = true
useInMemoryPgpKeys(privateKey, password)
sign(configurations.getByName("archives"))
}

// endregion
}
5 changes: 3 additions & 2 deletions dd-sdk-android-coil/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,6 +24,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -95,4 +96,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
5 changes: 3 additions & 2 deletions dd-sdk-android-fresco/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,6 +24,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -95,4 +96,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
5 changes: 3 additions & 2 deletions dd-sdk-android-glide/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,6 +25,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -99,4 +100,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
5 changes: 3 additions & 2 deletions dd-sdk-android-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,6 +24,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -97,4 +98,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
5 changes: 3 additions & 2 deletions dd-sdk-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,6 +24,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -131,4 +132,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
5 changes: 3 additions & 2 deletions dd-sdk-android-rx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,6 +23,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -94,4 +95,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
5 changes: 3 additions & 2 deletions dd-sdk-android-sqldelight/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,6 +23,7 @@ plugins {

// Publish
`maven-publish`
signing
id("org.jetbrains.dokka")

// Analysis tools
Expand Down Expand Up @@ -94,4 +95,4 @@ junitConfig()
jacocoConfig()
javadocConfig()
dependencyUpdateConfig()
mavenConfig()
publishingConfig()
Loading

0 comments on commit a57de3f

Please sign in to comment.