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

Adjust publications to publish gradle module metadata #3422

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 34 additions & 1 deletion 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, version = version)
}
from("build${sep}outputs${sep}aar") {
include("*-release*")
rename {
Expand Down Expand Up @@ -53,6 +56,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 +86,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
Loading