Skip to content

Commit

Permalink
Adjust publications to publish gradle module metadata (#3422)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed May 16, 2024
1 parent f1fdb9f commit 0a2d0b6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Features

- Publish Gradle module metadata ([#3422](https://github.com/getsentry/sentry-java/pull/3422))

## 7.9.0

### Features
Expand Down
11 changes: 1 addition & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
43 changes: 40 additions & 3 deletions buildSrc/src/main/java/Publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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*")
Expand All @@ -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")
Expand All @@ -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 {
Expand All @@ -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")
}
}
1 change: 1 addition & 0 deletions sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ dependencies {
if (applySentryIntegrations) {
implementation(projects.sentryAndroid)
implementation(projects.sentryCompose)
implementation(projects.sentryComposeHelper)
} else {
implementation(projects.sentryAndroidCore)
}
Expand Down
33 changes: 1 addition & 32 deletions sentry-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -44,7 +42,7 @@ kotlin {
compileOnly(compose.runtime)
compileOnly(compose.ui)

api(projects.sentryComposeHelper)
compileOnly(projects.sentryComposeHelper)
}
}
val androidMain by getting {
Expand Down Expand Up @@ -149,32 +147,3 @@ dependencies {
tasks.withType<LibraryAarJarsTask> {
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<PublishingExtension> {
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<Node>()
.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<GenerateModuleMetadata> {
enabled = false
}
1 change: 1 addition & 0 deletions sentry-samples/sentry-samples-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0a2d0b6

Please sign in to comment.