Skip to content

Commit 0be0d10

Browse files
authored
Move aar maven fix out of buildSrc (#2667)
1 parent ac1445b commit 0be0d10

File tree

3 files changed

+66
-77
lines changed

3 files changed

+66
-77
lines changed

build.gradle.kts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
21
import com.diffplug.spotless.LineEnding
32
import com.vanniktech.maven.publish.MavenPublishBaseExtension
43
import com.vanniktech.maven.publish.MavenPublishPlugin
54
import com.vanniktech.maven.publish.MavenPublishPluginExtension
5+
import groovy.util.Node
66
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
77
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
88
import org.gradle.api.tasks.testing.logging.TestLogEvent
@@ -224,3 +224,68 @@ gradle.taskGraph.whenReady {
224224
it.setExecutable(it.javaLauncher.get().executablePath.asFile.absolutePath)
225225
}
226226
}
227+
228+
private val androidLibs = setOf(
229+
"sentry-android-core",
230+
"sentry-android-ndk",
231+
"sentry-android-fragment",
232+
"sentry-android-navigation",
233+
"sentry-android-okhttp",
234+
"sentry-android-timber",
235+
"sentry-compose-android"
236+
)
237+
238+
private val androidXLibs = listOf(
239+
"androidx.core:core"
240+
)
241+
242+
/*
243+
* Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549
244+
*
245+
* Copyright 2018 The Android Open Source Project
246+
*
247+
* Licensed under the Apache License, Version 2.0 (the "License");
248+
* you may not use this file except in compliance with the License.
249+
* You may obtain a copy of the License at
250+
*
251+
* http://www.apache.org/licenses/LICENSE-2.0
252+
*
253+
* Unless required by applicable law or agreed to in writing, software
254+
* distributed under the License is distributed on an "AS IS" BASIS,
255+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
256+
* See the License for the specific language governing permissions and
257+
* limitations under the License.
258+
*/
259+
260+
// Workaround for https://github.com/gradle/gradle/issues/3170
261+
@Suppress("UnstableApiUsage")
262+
fun MavenPublishBaseExtension.assignAarTypes() {
263+
pom {
264+
withXml {
265+
val dependencies = asNode().children().find {
266+
it is Node && it.name().toString().endsWith("dependencies")
267+
} as Node?
268+
269+
dependencies?.children()?.forEach { dep ->
270+
if (dep !is Node) {
271+
return@forEach
272+
}
273+
val group = dep.children().firstOrNull {
274+
it is Node && it.name().toString().endsWith("groupId")
275+
} as? Node
276+
val groupValue = group?.children()?.firstOrNull() as? String
277+
278+
val artifactId = dep.children().firstOrNull {
279+
it is Node && it.name().toString().endsWith("artifactId")
280+
} as? Node
281+
val artifactIdValue = artifactId?.children()?.firstOrNull() as? String
282+
283+
if (artifactIdValue in androidLibs) {
284+
dep.appendNode("type", "aar")
285+
} else if ("$groupValue:$artifactIdValue" in androidXLibs) {
286+
dep.appendNode("type", "aar")
287+
}
288+
}
289+
}
290+
}
291+
}

buildSrc/build.gradle.kts

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

77
repositories {
88
mavenCentral()
9-
google()
109
}
1110

1211
tasks.withType<KotlinCompile>().configureEach {
1312
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
1413
}
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-
}

buildSrc/src/main/java/MavenPublication.kt

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)