Skip to content

Commit 0a2d0b6

Browse files
authored
Adjust publications to publish gradle module metadata (#3422)
1 parent f1fdb9f commit 0a2d0b6

File tree

7 files changed

+49
-45
lines changed

7 files changed

+49
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### Features
4+
5+
- Publish Gradle module metadata ([#3422](https://github.com/getsentry/sentry-java/pull/3422))
6+
37
## 7.9.0
48

59
### Features

build.gradle.kts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,7 @@ subprojects {
160160
if (this@subprojects.name.contains("-compose")) {
161161
this.configureForMultiplatform(this@subprojects)
162162
} else {
163-
this.getByName("main").contents {
164-
// non android modules
165-
from("build${sep}libs")
166-
from("build${sep}publications${sep}maven")
167-
// android modules
168-
from("build${sep}outputs${sep}aar") {
169-
include("*-release*")
170-
}
171-
from("build${sep}publications${sep}release")
172-
}
163+
this.configureForJvm(this@subprojects)
173164
}
174165
// craft only uses zip archives
175166
this.forEach { dist ->

buildSrc/src/main/java/Publication.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ private object Consts {
1010
// configure distZip tasks for multiplatform
1111
fun DistributionContainer.configureForMultiplatform(project: Project) {
1212
val sep = File.separator
13+
val version = project.properties["versionName"].toString()
1314

1415
this.maybeCreate("android").contents {
15-
from("build${sep}publications${sep}androidRelease")
16+
from("build${sep}publications${sep}androidRelease") {
17+
renameModule(project.name, "android", version = version)
18+
}
1619
from("build${sep}outputs${sep}aar") {
1720
include("*-release*")
1821
rename {
@@ -25,7 +28,9 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
2528
}
2629
}
2730
this.getByName("main").contents {
28-
from("build${sep}publications${sep}kotlinMultiplatform")
31+
from("build${sep}publications${sep}kotlinMultiplatform") {
32+
renameModule(project.name, version = version)
33+
}
2934
from("build${sep}kotlinToolingMetadata")
3035
from("build${sep}libs") {
3136
include("*compose-kotlin*")
@@ -39,7 +44,9 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
3944
}
4045
this.maybeCreate("desktop").contents {
4146
// kotlin multiplatform modules
42-
from("build${sep}publications${sep}desktop")
47+
from("build${sep}publications${sep}desktop") {
48+
renameModule(project.name, "desktop", version = version)
49+
}
4350
from("build${sep}libs") {
4451
include("*desktop*")
4552
withJavadoc(renameTo = "compose-desktop")
@@ -53,6 +60,26 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
5360
project.tasks.getByName("distZip").finalizedBy(*platformDists)
5461
}
5562

63+
fun DistributionContainer.configureForJvm(project: Project) {
64+
val sep = File.separator
65+
val version = project.properties["versionName"].toString()
66+
67+
this.getByName("main").contents {
68+
// non android modules
69+
from("build${sep}libs")
70+
from("build${sep}publications${sep}maven") {
71+
renameModule(project.name, version = version)
72+
}
73+
// android modules
74+
from("build${sep}outputs${sep}aar") {
75+
include("*-release*")
76+
}
77+
from("build${sep}publications${sep}release") {
78+
renameModule(project.name, version = version)
79+
}
80+
}
81+
}
82+
5683
private fun CopySpec.withJavadoc(renameTo: String = "compose") {
5784
include("*javadoc*")
5885
rename {
@@ -63,3 +90,13 @@ private fun CopySpec.withJavadoc(renameTo: String = "compose") {
6390
}
6491
}
6592
}
93+
94+
private fun CopySpec.renameModule(projectName: String, renameTo: String = "", version: String) {
95+
var target = ""
96+
if (renameTo.isNotEmpty()) {
97+
target = "-$renameTo"
98+
}
99+
rename {
100+
it.replace("module.json", "$projectName$target-$version.module")
101+
}
102+
}

sentry-android-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ dependencies {
7777
compileOnly(projects.sentryAndroidFragment)
7878
compileOnly(projects.sentryAndroidTimber)
7979
compileOnly(projects.sentryCompose)
80+
compileOnly(projects.sentryComposeHelper)
8081

8182
// lifecycle processor, session tracking
8283
implementation(Config.Libs.lifecycleProcess)

sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ dependencies {
9797
if (applySentryIntegrations) {
9898
implementation(projects.sentryAndroid)
9999
implementation(projects.sentryCompose)
100+
implementation(projects.sentryComposeHelper)
100101
} else {
101102
implementation(projects.sentryAndroidCore)
102103
}

sentry-compose/build.gradle.kts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import com.android.build.gradle.internal.tasks.LibraryAarJarsTask
2-
import groovy.util.Node
3-
import groovy.util.NodeList
42
import io.gitlab.arturbosch.detekt.Detekt
53
import org.jetbrains.dokka.gradle.DokkaTask
64

@@ -44,7 +42,7 @@ kotlin {
4442
compileOnly(compose.runtime)
4543
compileOnly(compose.ui)
4644

47-
api(projects.sentryComposeHelper)
45+
compileOnly(projects.sentryComposeHelper)
4846
}
4947
}
5048
val androidMain by getting {
@@ -149,32 +147,3 @@ dependencies {
149147
tasks.withType<LibraryAarJarsTask> {
150148
mainScopeClassFiles.setFrom(embedComposeHelperConfig)
151149
}
152-
153-
// we embed the sentry-compose-helper classes to the same .jar above
154-
// so we need to exclude the dependency from the .pom publication and .module metadata
155-
configure<PublishingExtension> {
156-
publications.withType(MavenPublication::class.java).all {
157-
this.pom {
158-
this.withXml {
159-
(asNode().get("dependencies") as NodeList)
160-
.flatMap {
161-
if (it is Node) it.children() else NodeList()
162-
}
163-
.filterIsInstance<Node>()
164-
.filter { dependency ->
165-
val artifactIdNodes = dependency.get("artifactId") as NodeList
166-
artifactIdNodes.any {
167-
(it is Node && it.value().toString().contains("sentry-compose-helper"))
168-
}
169-
}
170-
.forEach { dependency ->
171-
dependency.parent().remove(dependency)
172-
}
173-
}
174-
}
175-
}
176-
}
177-
178-
tasks.withType<GenerateModuleMetadata> {
179-
enabled = false
180-
}

sentry-samples/sentry-samples-android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ dependencies {
111111
implementation(projects.sentryAndroidFragment)
112112
implementation(projects.sentryAndroidTimber)
113113
implementation(projects.sentryCompose)
114+
implementation(projects.sentryComposeHelper)
114115
implementation(Config.Libs.fragment)
115116
implementation(Config.Libs.timber)
116117

0 commit comments

Comments
 (0)