diff --git a/CHANGELOG.md b/CHANGELOG.md index e43a16c245..bd532d181e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### Features + +- Publish Gradle module metadata ([#3422](https://github.com/getsentry/sentry-java/pull/3422)) + ## 7.9.0 ### Features diff --git a/build.gradle.kts b/build.gradle.kts index 42acafadb1..998c547efb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -160,16 +160,7 @@ subprojects { if (this@subprojects.name.contains("-compose")) { this.configureForMultiplatform(this@subprojects) } else { - this.getByName("main").contents { - // non android modules - from("build${sep}libs") - from("build${sep}publications${sep}maven") - // android modules - from("build${sep}outputs${sep}aar") { - include("*-release*") - } - from("build${sep}publications${sep}release") - } + this.configureForJvm(this@subprojects) } // craft only uses zip archives this.forEach { dist -> diff --git a/buildSrc/src/main/java/Publication.kt b/buildSrc/src/main/java/Publication.kt index 1362e96522..08a81c703f 100644 --- a/buildSrc/src/main/java/Publication.kt +++ b/buildSrc/src/main/java/Publication.kt @@ -10,9 +10,12 @@ private object Consts { // configure distZip tasks for multiplatform fun DistributionContainer.configureForMultiplatform(project: Project) { val sep = File.separator + val version = project.properties["versionName"].toString() this.maybeCreate("android").contents { - from("build${sep}publications${sep}androidRelease") + from("build${sep}publications${sep}androidRelease") { + renameModule(project.name, "android", version = version) + } from("build${sep}outputs${sep}aar") { include("*-release*") rename { @@ -25,7 +28,9 @@ fun DistributionContainer.configureForMultiplatform(project: Project) { } } this.getByName("main").contents { - from("build${sep}publications${sep}kotlinMultiplatform") + from("build${sep}publications${sep}kotlinMultiplatform") { + renameModule(project.name, version = version) + } from("build${sep}kotlinToolingMetadata") from("build${sep}libs") { include("*compose-kotlin*") @@ -39,7 +44,9 @@ fun DistributionContainer.configureForMultiplatform(project: Project) { } this.maybeCreate("desktop").contents { // kotlin multiplatform modules - from("build${sep}publications${sep}desktop") + from("build${sep}publications${sep}desktop") { + renameModule(project.name, "desktop", version = version) + } from("build${sep}libs") { include("*desktop*") withJavadoc(renameTo = "compose-desktop") @@ -53,6 +60,26 @@ fun DistributionContainer.configureForMultiplatform(project: Project) { project.tasks.getByName("distZip").finalizedBy(*platformDists) } +fun DistributionContainer.configureForJvm(project: Project) { + val sep = File.separator + val version = project.properties["versionName"].toString() + + this.getByName("main").contents { + // non android modules + from("build${sep}libs") + from("build${sep}publications${sep}maven") { + renameModule(project.name, version = version) + } + // android modules + from("build${sep}outputs${sep}aar") { + include("*-release*") + } + from("build${sep}publications${sep}release") { + renameModule(project.name, version = version) + } + } +} + private fun CopySpec.withJavadoc(renameTo: String = "compose") { include("*javadoc*") rename { @@ -63,3 +90,13 @@ private fun CopySpec.withJavadoc(renameTo: String = "compose") { } } } + +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") + } +} diff --git a/sentry-android-core/build.gradle.kts b/sentry-android-core/build.gradle.kts index 4ab0aec423..2ec856cf5f 100644 --- a/sentry-android-core/build.gradle.kts +++ b/sentry-android-core/build.gradle.kts @@ -77,6 +77,7 @@ dependencies { compileOnly(projects.sentryAndroidFragment) compileOnly(projects.sentryAndroidTimber) compileOnly(projects.sentryCompose) + compileOnly(projects.sentryComposeHelper) // lifecycle processor, session tracking implementation(Config.Libs.lifecycleProcess) diff --git a/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts b/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts index 16f6b9b9ad..98b00eb4f8 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts +++ b/sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts @@ -97,6 +97,7 @@ dependencies { if (applySentryIntegrations) { implementation(projects.sentryAndroid) implementation(projects.sentryCompose) + implementation(projects.sentryComposeHelper) } else { implementation(projects.sentryAndroidCore) } diff --git a/sentry-compose/build.gradle.kts b/sentry-compose/build.gradle.kts index 1291ea1696..114c08a22f 100644 --- a/sentry-compose/build.gradle.kts +++ b/sentry-compose/build.gradle.kts @@ -1,6 +1,4 @@ import com.android.build.gradle.internal.tasks.LibraryAarJarsTask -import groovy.util.Node -import groovy.util.NodeList import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.dokka.gradle.DokkaTask @@ -44,7 +42,7 @@ kotlin { compileOnly(compose.runtime) compileOnly(compose.ui) - api(projects.sentryComposeHelper) + compileOnly(projects.sentryComposeHelper) } } val androidMain by getting { @@ -149,32 +147,3 @@ dependencies { tasks.withType { mainScopeClassFiles.setFrom(embedComposeHelperConfig) } - -// we embed the sentry-compose-helper classes to the same .jar above -// so we need to exclude the dependency from the .pom publication and .module metadata -configure { - publications.withType(MavenPublication::class.java).all { - this.pom { - this.withXml { - (asNode().get("dependencies") as NodeList) - .flatMap { - if (it is Node) it.children() else NodeList() - } - .filterIsInstance() - .filter { dependency -> - val artifactIdNodes = dependency.get("artifactId") as NodeList - artifactIdNodes.any { - (it is Node && it.value().toString().contains("sentry-compose-helper")) - } - } - .forEach { dependency -> - dependency.parent().remove(dependency) - } - } - } - } -} - -tasks.withType { - enabled = false -} diff --git a/sentry-samples/sentry-samples-android/build.gradle.kts b/sentry-samples/sentry-samples-android/build.gradle.kts index ac77791268..a8d8897519 100644 --- a/sentry-samples/sentry-samples-android/build.gradle.kts +++ b/sentry-samples/sentry-samples-android/build.gradle.kts @@ -111,6 +111,7 @@ dependencies { implementation(projects.sentryAndroidFragment) implementation(projects.sentryAndroidTimber) implementation(projects.sentryCompose) + implementation(projects.sentryComposeHelper) implementation(Config.Libs.fragment) implementation(Config.Libs.timber)