-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💚 Update Maven publishing script (second try)
- Loading branch information
Showing
11 changed files
with
73 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.