diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dcbf90d..742fba85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Internal + +- Update `distZip` task to use the locally published artifacts via `publishToMavenLocal` ([#425](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/425)) + ## 0.15.0 ### Enhancements diff --git a/build.gradle.kts b/build.gradle.kts index c794d01c..28338309 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,16 +31,19 @@ subprojects { apply() val sep = File.separator + // The path where we want publishToMavenLocal to output the artifacts to + val buildPublishDir = "${project.layout.buildDirectory.get().asFile.path}${sep}sentry-local-publish$sep" configure { - this.configureForMultiplatform(this@subprojects) + configureForMultiplatform(this@subprojects, buildPublishDir) } tasks.named("distZip").configure { - this.dependsOn("publishToMavenLocal") - this.doLast { + System.setProperty("maven.repo.local", buildPublishDir) + dependsOn("publishToMavenLocal") + doLast { val distributionFilePath = - "${this.project.buildDir}${sep}distributions${sep}${this.project.name}-${this.project.version}.zip" + "${project.layout.buildDirectory.get().asFile.path}${sep}distributions${sep}${project.name}-${project.version}.zip" val file = File(distributionFilePath) if (!file.exists()) throw GradleException("Distribution file: $distributionFilePath does not exist") if (file.length() == 0L) throw GradleException("Distribution file: $distributionFilePath is empty") diff --git a/buildSrc/src/main/java/Publication.kt b/buildSrc/src/main/java/Publication.kt index 68fddaeb..a983c071 100644 --- a/buildSrc/src/main/java/Publication.kt +++ b/buildSrc/src/main/java/Publication.kt @@ -1,228 +1,47 @@ +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.distribution.DistributionContainer -import org.gradle.api.file.CopySpec import java.io.File -val sep: String = File.separator +private val sep: String = File.separator -// configure distZip tasks for multiplatform -fun DistributionContainer.configureForMultiplatform(project: Project) { - val version = project.properties["versionName"].toString() - this.getByName("main").contents { - from("build${sep}publications${sep}kotlinMultiplatform") { - renameModule(project.name, version = version) - } - // The current Kotlin version doesn't generate this *-all.jar anymore. - // This is a placeholder for backwards compatibility with craft until we fix it there directly. - from("build${sep}libs") { - include("${project.name}-metadata-$version*") - rename { - it.replace("metadata-$version", "$version-all") - } - } - from("build${sep}kotlinToolingMetadata") { - rename { - it.replace( - "kotlin-tooling-metadata.json", - "${project.name}-$version-kotlin-tooling-metadata.json" - ) - } - } - from("build${sep}libs") { - include("${project.name}-kotlin*") - include("${project.name}-metadata*") - withJavadoc(project.name) - rename { - it.replace("multiplatform-kotlin", "multiplatform").replace("-metadata", "") - } - } - } - this.maybeCreate("android").contents { - from("build${sep}publications${sep}androidRelease") { - renameModule(project.name, "android", version) - } - from("build${sep}outputs${sep}aar${sep}${project.name}-release.aar") { - rename { - it.replace("-release", "-android-release") - } - } - from("build${sep}libs") { - include("*android*") - withJavadoc(project.name, "android") - } - } - this.maybeCreate("jvm").contents { - from("build${sep}publications${sep}jvm") { - renameModule(project.name, "jvm", version) - } - from("build${sep}libs$sep") { - include("*jvm*") - withJavadoc(project.name, "jvm") - } - } - this.maybeCreate("iosarm64").contents { - from("build${sep}publications${sep}iosArm64") { - renameModule(project.name, "iosarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-iosarm64*") - withJavadoc(project.name, "iosarm64") - } - fromKlib(project.name, "iosArm64", version) - } - this.maybeCreate("iosx64").contents { - from("build${sep}publications${sep}iosX64") { - renameModule(project.name, "iosx64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-iosx64*") - withJavadoc(project.name, "iosx64") - } - fromKlib(project.name, "iosX64", version) - } - this.maybeCreate("iossimulatorarm64").contents { - from("build${sep}publications${sep}iosSimulatorArm64") { - renameModule(project.name, "iossimulatorarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-iossimulatorarm64*") - withJavadoc(project.name, "iossimulatorarm64") - } - fromKlib(project.name, "iosSimulatorArm64", version) - } - this.maybeCreate("macosarm64").contents { - from("build${sep}publications${sep}macosArm64") { - renameModule(project.name, "macosarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-macosarm64*") - withJavadoc(project.name, "macosarm64") - } - fromKlib(project.name, "macosArm64", version) - } - this.maybeCreate("macosx64").contents { - from("build${sep}publications${sep}macosX64") { - renameModule(project.name, "macosx64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-macosx64*") - withJavadoc(project.name, "macosx64") - } - fromKlib(project.name, "macosX64", version) - } - this.maybeCreate("watchosx64").contents { - from("build${sep}publications${sep}watchosX64") { - renameModule(project.name, "watchosx64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-watchosx64*") - withJavadoc(project.name, "watchosx64") - } - fromKlib(project.name, "watchosX64", version) - } - this.maybeCreate("watchosarm32").contents { - from("build${sep}publications${sep}watchosArm32") { - renameModule(project.name, "watchosarm32", version) - } - from("build${sep}libs$sep") { - include("${project.name}-watchosarm32*") - withJavadoc(project.name, "watchosarm32") - } - fromKlib(project.name, "watchosArm32", version) - } - this.maybeCreate("watchosarm64").contents { - from("build${sep}publications${sep}watchosArm64") { - renameModule(project.name, "watchosarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-watchosarm64*") - withJavadoc(project.name, "watchosarm64") - } - fromKlib(project.name, "watchosArm64", version) - } - this.maybeCreate("watchossimulatorarm64").contents { - from("build${sep}publications${sep}watchosSimulatorArm64") { - renameModule(project.name, "watchossimulatorarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-watchossimulatorarm64*") - withJavadoc(project.name, "watchossimulatorarm64") - } - fromKlib(project.name, "watchosSimulatorArm64", version) - } - this.maybeCreate("tvosarm64").contents { - from("build${sep}publications${sep}tvosArm64") { - renameModule(project.name, "tvosarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-tvosarm64*") - withJavadoc(project.name, "tvosarm64") - } - fromKlib(project.name, "tvosArm64", version) - } - this.maybeCreate("tvosx64").contents { - from("build${sep}publications${sep}tvosX64") { - renameModule(project.name, "tvosx64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-tvosx64*") - withJavadoc(project.name, "tvosx64") - } - fromKlib(project.name, "tvosX64", version) - } - this.maybeCreate("tvossimulatorarm64").contents { - from("build${sep}publications${sep}tvosSimulatorArm64") { - renameModule(project.name, "tvossimulatorarm64", version) - } - from("build${sep}libs$sep") { - include("${project.name}-tvossimulatorarm64*") - withJavadoc(project.name, "tvossimulatorarm64") - } - fromKlib(project.name, "tvosSimulatorArm64", version) - } -} +fun DistributionContainer.configureForMultiplatform(project: Project, buildPublishDir: String) { + val version = project.property("versionName").toString() + if (version.isEmpty()) { + throw GradleException("DistZip: version name is empty") + } + val projectName = project.name + val platforms = mapOf( + "main" to projectName, + "android" to "$projectName-android", + "jvm" to "$projectName-jvm", + "iosarm64" to "$projectName-iosarm64", + "iossimulatorarm64" to "$projectName-iossimulatorarm64", + "iosx64" to "$projectName-iosx64", + "macosarm64" to "$projectName-macosarm64", + "macosx64" to "$projectName-macosx64", + "tvosarm64" to "$projectName-tvosarm64", + "tvossimulatorarm64" to "$projectName-tvossimulatorarm64", + "tvosx64" to "$projectName-tvosx64", + "watchosarm32" to "$projectName-watchosarm32", + "watchosarm64" to "$projectName-watchosarm64", + "watchossimulatorarm64" to "$projectName-watchossimulatorarm64", + "watchosx64" to "$projectName-watchosx64" + ) -private fun CopySpec.fromKlib(projectName: String, target: String, version: String) { - val pos = projectName.length - from("build${sep}classes${sep}kotlin${sep}${target}${sep}main${sep}cinterop") { - include("*.klib") - rename { - it.replaceRange(pos, pos, "-${target.lowercase()}-$version") - } - } - from("build${sep}classes${sep}kotlin${sep}${target}${sep}main${sep}klib") { - rename { - "$projectName-${target.lowercase()}-$version.klib" - } - } -} + platforms.forEach { (distName, projectName) -> + val distribution = maybeCreate(distName) + distribution.contents { + val basePath = "${buildPublishDir}io${sep}sentry${sep}$projectName$sep$version" -private fun CopySpec.renameModule(projectName: String, renameTo: String = "", version: String) { - var target = "" - if (renameTo.isNotEmpty()) { - target = "-$renameTo" - } - rename { - it.replace("module.json", "$projectName$target-$version.module") - } -} + // Rename the POM since craft looks for pom-default.xml + from("$basePath$sep$projectName-$version.pom") { + rename { "pom-default.xml" } + } -private fun CopySpec.withJavadoc(projectName: String, renameTo: String = "") { - include("*javadoc*") - rename { fileName -> - when { - "javadoc" in fileName -> { - val newName = buildString { - append(fileName.substring(0, projectName.length)) - if (renameTo.isNotEmpty()) { - append('-') - append(renameTo) - } - append(fileName.substring(projectName.length)) - } - newName + from(basePath) { + exclude("*.pom") } - else -> fileName } } }