|
1 | | - |
2 | 1 | import com.diffplug.spotless.LineEnding |
3 | 2 | import com.vanniktech.maven.publish.MavenPublishBaseExtension |
4 | 3 | import com.vanniktech.maven.publish.MavenPublishPlugin |
5 | 4 | import com.vanniktech.maven.publish.MavenPublishPluginExtension |
| 5 | +import groovy.util.Node |
6 | 6 | import io.gitlab.arturbosch.detekt.extensions.DetektExtension |
7 | 7 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
8 | 8 | import org.gradle.api.tasks.testing.logging.TestLogEvent |
@@ -224,3 +224,68 @@ gradle.taskGraph.whenReady { |
224 | 224 | it.setExecutable(it.javaLauncher.get().executablePath.asFile.absolutePath) |
225 | 225 | } |
226 | 226 | } |
| 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 | +} |
0 commit comments