From 0be0d10a9fc61369a551c3b90134fe36c050a584 Mon Sep 17 00:00:00 2001 From: Roman Zavarnitsyn Date: Mon, 24 Apr 2023 10:41:25 +0200 Subject: [PATCH] Move aar maven fix out of buildSrc (#2667) --- build.gradle.kts | 67 ++++++++++++++++++++- buildSrc/build.gradle.kts | 7 --- buildSrc/src/main/java/MavenPublication.kt | 69 ---------------------- 3 files changed, 66 insertions(+), 77 deletions(-) delete mode 100644 buildSrc/src/main/java/MavenPublication.kt diff --git a/build.gradle.kts b/build.gradle.kts index 7a2936607e..f2d976c661 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ - import com.diffplug.spotless.LineEnding import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.MavenPublishPlugin import com.vanniktech.maven.publish.MavenPublishPluginExtension +import groovy.util.Node import io.gitlab.arturbosch.detekt.extensions.DetektExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent @@ -224,3 +224,68 @@ gradle.taskGraph.whenReady { it.setExecutable(it.javaLauncher.get().executablePath.asFile.absolutePath) } } + +private val androidLibs = setOf( + "sentry-android-core", + "sentry-android-ndk", + "sentry-android-fragment", + "sentry-android-navigation", + "sentry-android-okhttp", + "sentry-android-timber", + "sentry-compose-android" +) + +private val androidXLibs = listOf( + "androidx.core:core" +) + +/* + * Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549 + * + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Workaround for https://github.com/gradle/gradle/issues/3170 +@Suppress("UnstableApiUsage") +fun MavenPublishBaseExtension.assignAarTypes() { + pom { + withXml { + val dependencies = asNode().children().find { + it is Node && it.name().toString().endsWith("dependencies") + } as Node? + + dependencies?.children()?.forEach { dep -> + if (dep !is Node) { + return@forEach + } + val group = dep.children().firstOrNull { + it is Node && it.name().toString().endsWith("groupId") + } as? Node + val groupValue = group?.children()?.firstOrNull() as? String + + val artifactId = dep.children().firstOrNull { + it is Node && it.name().toString().endsWith("artifactId") + } as? Node + val artifactIdValue = artifactId?.children()?.firstOrNull() as? String + + if (artifactIdValue in androidLibs) { + dep.appendNode("type", "aar") + } else if ("$groupValue:$artifactIdValue" in androidXLibs) { + dep.appendNode("type", "aar") + } + } + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 4b45e2084f..5d8cbb335f 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -6,15 +6,8 @@ plugins { repositories { mavenCentral() - google() } tasks.withType().configureEach { kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString() } - -dependencies { - implementation("com.vanniktech:gradle-maven-publish-plugin:0.18.0") - implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.6.10") - implementation("com.android.tools.build:gradle:7.3.0") -} diff --git a/buildSrc/src/main/java/MavenPublication.kt b/buildSrc/src/main/java/MavenPublication.kt deleted file mode 100644 index e1d5b26106..0000000000 --- a/buildSrc/src/main/java/MavenPublication.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549 - * - * Copyright 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import com.vanniktech.maven.publish.MavenPublishBaseExtension -import groovy.util.Node - -private val androidLibs = setOf( - "sentry-android-core", - "sentry-android-ndk", - "sentry-android-fragment", - "sentry-android-navigation", - "sentry-android-okhttp", - "sentry-android-timber", - "sentry-compose-android" -) - -private val androidXLibs = listOf( - "androidx.core:core", - "androidx.lifecycle:lifecycle-process", - "androidx.lifecycle:lifecycle-common-java8" -) - -@Suppress("UnstableApiUsage") -fun MavenPublishBaseExtension.assignAarTypes() { - pom { - withXml { - // workaround for https://github.com/gradle/gradle/issues/3170 - val dependencies = asNode().children().find { - it is Node && it.name().toString().endsWith("dependencies") - } as Node? - - dependencies?.children()?.forEach { dep -> - if (dep !is Node) { - return@forEach - } - val group = dep.children().firstOrNull { - it is Node && it.name().toString().endsWith("groupId") - } as? Node - val groupValue = group?.children()?.firstOrNull() as? String - - val artifactId = dep.children().firstOrNull { - it is Node && it.name().toString().endsWith("artifactId") - } as? Node - val artifactIdValue = artifactId?.children()?.firstOrNull() as? String - - if (artifactIdValue in androidLibs) { - dep.appendNode("type", "aar") - } else if ("$groupValue:$artifactIdValue" in androidXLibs) { - dep.appendNode("type", "aar") - } - } - } - } -}