Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New publish to Maven Central Portal #494

Merged
merged 11 commits into from
Sep 19, 2024
69 changes: 69 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import com.jetbrains.rd.gradle.dependencies.kotlinVersion
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.asRequestBody
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*

buildscript {
dependencies {
classpath("com.squareup.okhttp3:okhttp:4.12.0")
}
project.extra.apply {
val repoRoot = rootProject.projectDir
set("repoRoot", repoRoot)
Expand Down Expand Up @@ -177,7 +185,68 @@ tasks {
}
}

val packSonatypeCentralBundle by registering(Zip::class) {
group = publishingGroup

dependsOn(
":rd-core:publishAllPublicationsToArtifactsRepository",
":rd-framework:publishAllPublicationsToArtifactsRepository",
":rd-gen:publishAllPublicationsToArtifactsRepository",
":rd-swing:publishAllPublicationsToArtifactsRepository",
":rd-text:publishAllPublicationsToArtifactsRepository"
)

from(layout.buildDirectory.dir("artifacts/maven"))
archiveFileName.set("bundle.zip")
destinationDirectory.set(layout.buildDirectory)
}

val publishMavenToCentralPortal by registering {
group = publishingGroup

dependsOn(packSonatypeCentralBundle)

doLast {
val uriBase = rootProject.extra["centralPortalApiUrl"] as String
val publicationType = "USER_MANAGED"
val deploymentName = "rd-$version"
val uri = "$uriBase?name=$deploymentName&publicationType=$publicationType"

val userName = rootProject.extra["centralPortalUserName"] as String
val token = rootProject.extra["centralPortalToken"] as String
val base64Auth = Base64.getEncoder().encode("$userName:$token".toByteArray()).toString(Charsets.UTF_8)
val bundleFile = packSonatypeCentralBundle.get().archiveFile.get().asFile

println("Sending request to $uri...")

val client = OkHttpClient()
val request = Request.Builder()
.url(uri)
.header("Authorization", "Bearer $base64Auth")
.post(
MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("bundle", bundleFile.name, bundleFile.asRequestBody())
.build()
)
.build()
val response = client.newCall(request).execute()

val statusCode = response.code
println("Upload status code: $statusCode")
println("Upload result: ${response.body!!.string()}")
if (statusCode != 201) {
error("Upload error to Central repository. Status code $statusCode.")
}
}
}

named("publish") {
dependsOn(publishNuGet)

val deployToCentral = rootProject.extra["deployMavenToCentralPortal"].toString().toBoolean()
if (deployToCentral) {
dependsOn(publishMavenToCentralPortal)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ open class KotlinJVMPlugin : Plugin<Project> {
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "signing")

group = "com.jetbrains.rd"

configure<KotlinJvmProjectExtension> {
val sourceJar by tasks.creating(Jar::class) {
from(sourceSets["main"].kotlin.sourceDirectories)
Expand All @@ -50,11 +52,10 @@ open class KotlinJVMPlugin : Plugin<Project> {
enabled = false
}

configure<PublishingExtension> {
publications {
if (project.name != "rd-cross") {
if (project.name != "rd-cross") {
configure<PublishingExtension> {
publications {
register("pluginMaven", MavenPublication::class.java) {
groupId = "com.jetbrains.rd"
artifactId = project.name
version = rootProject.version as String

Expand Down Expand Up @@ -91,46 +92,34 @@ open class KotlinJVMPlugin : Plugin<Project> {
artifact(packageJavadoc)
}
}
}

val isUnderTeamCity = System.getenv("TEAMCITY_VERSION") != null
project.configure<SigningExtension> {
if (isUnderTeamCity) {
sign(publications)
signatories = GpgSignSignatoryProvider()
}
}
val deployToIntelliJ = rootProject.extra["deployMavenToIntelliJDependencies"].toString().toBoolean()
val deployToSonatype = rootProject.extra["deployMavenToSonatype"].toString().toBoolean()
repositories {
maven {
name = "artifacts"
url = uri(rootProject.projectDir.resolve("build").resolve("artifacts").resolve("maven"))
}
if (deployToIntelliJ) {
maven {
name = "intellij-dependencies"
url = uri("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies/")
credentials {
username = "Bearer"
password = rootProject.extra["internalDeployKey"].toString()
}
val isUnderTeamCity = System.getenv("TEAMCITY_VERSION") != null
project.configure<SigningExtension> {
if (isUnderTeamCity) {
sign(publications)
signatories = GpgSignSignatoryProvider()
}
}
if (deployToSonatype) {
val deployToIntelliJ = rootProject.extra["deployMavenToIntelliJDependencies"].toString().toBoolean()
repositories {
maven {
name = "maven-central"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = rootProject.extra["sonatypeUser"].toString()
password = rootProject.extra["sonatypePassword"].toString()
name = "artifacts"
url = uri(rootProject.projectDir.resolve("build").resolve("artifacts").resolve("maven"))
}
if (deployToIntelliJ) {
maven {
name = "intellij-dependencies"
url = uri("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies/")
credentials {
username = "Bearer"
password = rootProject.extra["internalDeployKey"].toString()
}
}
}
}
}
}


val test by tasks.getting(Test::class) {
maxHeapSize = "512m"
useJUnitPlatform()
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
org.gradle.jvmargs=-Xmx1024m

version=2024.3-pre2
version=2024.3.0

deployMavenToIntelliJDependencies=false
deployMavenToSonatype=false
deployMavenToCentralPortal=false
deployNuGetToNuGetOrg=false
deployNuGetToInternal=false

centralPortalApiUrl=https://central.sonatype.com/api/v1/publisher/upload
Loading