Skip to content

Commit e9e1695

Browse files
authored
Fix aar artifacts publication for Maven (#2641)
1 parent 4d04310 commit e9e1695

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Fix timestamps of PerformanceCollectionData in profiles ([#2632](https://github.com/getsentry/sentry-java/pull/2632))
1616
- Fix missing propagateMinConstraints flag for SentryTraced ([#2637](https://github.com/getsentry/sentry-java/pull/2637))
1717
- Fix potential SecurityException thrown by ConnectivityManager on Android 11 ([#2653](https://github.com/getsentry/sentry-java/pull/2653))
18+
- Fix aar artifacts publishing for Maven ([#2641](https://github.com/getsentry/sentry-java/pull/2641))
1819

1920
### Dependencies
2021
- Bump Kotlin compile version from v1.6.10 to 1.8.0 ([#2563](https://github.com/getsentry/sentry-java/pull/2563))

build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import com.diffplug.spotless.LineEnding
3+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
34
import com.vanniktech.maven.publish.MavenPublishPlugin
45
import com.vanniktech.maven.publish.MavenPublishPluginExtension
56
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
@@ -154,6 +155,11 @@ subprojects {
154155
releaseSigningEnabled = false
155156
}
156157

158+
@Suppress("UnstableApiUsage")
159+
configure<MavenPublishBaseExtension> {
160+
assignAarTypes()
161+
}
162+
157163
// maven central info go to:
158164
// ~/.gradle/gradle.properties
159165

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ plugins {
66

77
repositories {
88
mavenCentral()
9+
google()
910
}
1011

1112
tasks.withType<KotlinCompile>().configureEach {
1213
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
1314
}
15+
16+
dependencies {
17+
implementation("com.vanniktech:gradle-maven-publish-plugin:0.18.0")
18+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.6.10")
19+
implementation("com.android.tools.build:gradle:7.3.0")
20+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549
3+
*
4+
* Copyright 2018 The Android Open Source Project
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
20+
import groovy.util.Node
21+
22+
private val androidLibs = setOf(
23+
"sentry-android-core",
24+
"sentry-android-ndk",
25+
"sentry-android-fragment",
26+
"sentry-android-navigation",
27+
"sentry-android-okhttp",
28+
"sentry-android-timber",
29+
"sentry-compose-android"
30+
)
31+
32+
private val androidXLibs = listOf(
33+
"androidx.core:core",
34+
"androidx.lifecycle:lifecycle-process",
35+
"androidx.lifecycle:lifecycle-common-java8"
36+
)
37+
38+
@Suppress("UnstableApiUsage")
39+
fun MavenPublishBaseExtension.assignAarTypes() {
40+
pom {
41+
withXml {
42+
// workaround for https://github.com/gradle/gradle/issues/3170
43+
val dependencies = asNode().children().find {
44+
it is Node && it.name().toString().endsWith("dependencies")
45+
} as Node?
46+
47+
dependencies?.children()?.forEach { dep ->
48+
if (dep !is Node) {
49+
return@forEach
50+
}
51+
val group = dep.children().firstOrNull {
52+
it is Node && it.name().toString().endsWith("groupId")
53+
} as? Node
54+
val groupValue = group?.children()?.firstOrNull() as? String
55+
56+
val artifactId = dep.children().firstOrNull {
57+
it is Node && it.name().toString().endsWith("artifactId")
58+
} as? Node
59+
val artifactIdValue = artifactId?.children()?.firstOrNull() as? String
60+
61+
if (artifactIdValue in androidLibs) {
62+
dep.appendNode("type", "aar")
63+
} else if ("$groupValue:$artifactIdValue" in androidXLibs) {
64+
dep.appendNode("type", "aar")
65+
}
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)