|
| 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