Skip to content

Commit

Permalink
Move aar maven fix out of buildSrc (#2667)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn authored Apr 24, 2023
1 parent ac1445b commit 0be0d10
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 77 deletions.
67 changes: 66 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
}
}
}
}
}
7 changes: 0 additions & 7 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@ plugins {

repositories {
mavenCentral()
google()
}

tasks.withType<KotlinCompile>().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")
}
69 changes: 0 additions & 69 deletions buildSrc/src/main/java/MavenPublication.kt

This file was deleted.

0 comments on commit 0be0d10

Please sign in to comment.