Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,34 @@ limitations under the License.

---

## Android Open Source Project — AndroidX MavenUploadHelper (Apache 2.0)

**Source:** https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549<br>
**License:** Apache License 2.0<br>
**Copyright:** Copyright 2018 The Android Open Source Project

### Scope

The Sentry Java SDK build includes an adapted version of the AndroidX build's POM rewriting, which adds `<type>aar</type>` to dependencies on Android libraries in published POMs. The code resides in the build logic at `build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt` and is not part of the published artifacts.

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

---

## OpenTelemetry (Apache 2.0)

**Source:** https://github.com/open-telemetry/opentelemetry-java (Commit: 0aacc55d1e3f5cc6dbb4f8fa26bcb657b01a7bc9)<br>
Expand Down
14 changes: 14 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {
dependencies {
implementation(libs.animalsniffer.gradle.plugin)
implementation(libs.spotlessLib)
implementation(libs.detektLib)
implementation(libs.vanniktechMavenPublishLib)
implementation(libs.asm)
compileOnly(libs.kotlin.gradle.plugin)
compileOnly(libs.android.gradle.plugin)
Expand All @@ -16,6 +18,18 @@ gradlePlugin {
id = "io.sentry.jdk-target"
implementationClass = "io.sentry.gradle.JdkTargetConvention"
}
register("sentryDetekt") {
id = "io.sentry.detekt"
implementationClass = "io.sentry.gradle.SentryDetektPlugin"
}
register("sentryPublish") {
id = "io.sentry.publish"
implementationClass = "io.sentry.gradle.SentryPublishPlugin"
}
register("sentryMultiplatformPublish") {
id = "io.sentry.publish.multiplatform"
implementationClass = "io.sentry.gradle.SentryMultiplatformPublishPlugin"
}
register("sentryApiValidation") {
id = "io.sentry.api-validation"
implementationClass = "io.sentry.gradle.SentryApiValidationPlugin"
Expand Down
69 changes: 69 additions & 0 deletions build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Resolved

package io.sentry.gradle

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import groovy.util.Node

private val androidLibs =
Comment thread
markushi marked this conversation as resolved.
Resolved
setOf(
"sentry-android-core",
"sentry-android-ndk",
"sentry-android-fragment",
"sentry-android-navigation",
"sentry-android-navigation3",
"sentry-android-timber",
"sentry-compose-android",
"sentry-android-sqlite",
"sentry-android-replay",
)

private val androidXLibs = listOf("androidx.core:core")

// Workaround for https://github.com/gradle/gradle/issues/3170
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")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package io.sentry.gradle
Comment thread
markushi marked this conversation as resolved.
Resolved

import org.gradle.api.Project
import org.gradle.api.distribution.DistributionContainer
import org.gradle.api.file.CopySpec
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.sentry.gradle

import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

/** Runs detekt on a module against the shared ruleset, with a per-module baseline. */
class SentryDetektPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.pluginManager.apply("io.gitlab.arturbosch.detekt")

project.extensions.configure<DetektExtension> {
buildUponDefaultConfig = true
allRules = true
config.setFrom(project.isolated.rootProject.projectDirectory.file("detekt.yml"))
baseline = project.file("detekt-baseline.xml")
Comment thread
markushi marked this conversation as resolved.
Resolved
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package io.sentry.gradle

import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import java.io.File
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.distribution.DistributionContainer
import org.gradle.api.distribution.plugins.DistributionPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.kotlin.dsl.configure

/** Publishes a JVM or Android module and packages it as the zip distribution craft consumes. */
class SentryPublishPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.configurePublishing(DistributionContainer::configureForJvm)
}
}

/**
* Publishes a Kotlin Multiplatform module. Separate from [SentryPublishPlugin] because the
* per-target distributions it lays out have no counterpart in a single-target module.
*/
class SentryMultiplatformPublishPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.configurePublishing(DistributionContainer::configureForMultiplatform)
}
}

private fun Project.configurePublishing(
configureDistributions: DistributionContainer.(Project) -> Unit
) {
pluginManager.apply(DistributionPlugin::class.java)
pluginManager.apply("com.vanniktech.maven.publish")

extensions.configure<DistributionContainer> {
configureDistributions(project)
// craft only uses zip archives
forEach { dist ->
if (dist.name == DistributionPlugin.MAIN_DISTRIBUTION_NAME) {
tasks.named("distTar").configure { enabled = false }
} else {
tasks.named(dist.name + "DistTar").configure { enabled = false }
}
}
}

val sep = File.separator
val distributionFile =
layout.buildDirectory.file("distributions$sep$name-$version.zip").get().asFile

tasks.named("distZip").configure {
dependsOn("publishToMavenLocal")
dependsOn("publishAllPublicationsTo${DIST_MAVEN_REPO.replaceFirstChar { it.uppercase() }}Repository")
val file = distributionFile
doLast {
if (!file.exists()) {
throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
}
if (file.length() == 0L) {
throw IllegalStateException("Distribution file: ${file.absolutePath} is empty")
}
}
}

extensions.configure<MavenPublishBaseExtension> { assignAarTypes() }

plugins.withId("java-library") {
extensions.configure<MavenPublishBaseExtension> {
// we have to disable javadoc publication in maven-publish plugin as it's not
// including it in the .module file
Comment thread
markushi marked this conversation as resolved.
Resolved
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861
// and do it ourselves
configure(JavaLibrary(JavadocJar.None(), sourcesJar = true))
}

extensions.configure<JavaPluginExtension> { withJavadocJar() }
}

extensions.configure<PublishingExtension> {
// the dist zips craft publishes are assembled from this, see Publication.kt
repositories.maven {
name = DIST_MAVEN_REPO
url = distMavenDir.get().asFile.toURI()
}
// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
repositories.maven {
name = "unityMaven"
url = isolated.rootProject.projectDirectory.dir("build${sep}unityMaven").asFile.toURI()
}
}
}
Loading
Loading