Skip to content
Draft
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
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)
compileOnly(libs.kotlin.gradle.plugin)
compileOnly(libs.android.gradle.plugin)
}
Expand All @@ -15,6 +17,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("sentryAnimalSniffer") {
id = "io.sentry.animalsniffer"
implementationClass = "io.sentry.gradle.SentryAnimalSnifferPlugin"
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.
*/

Check warning on line 17 in build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt

View check run for this annotation

@sentry/warden / warden: check-code-attribution

⚠️ Missing THIRD_PARTY_NOTICES.md entry

**build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt** — This file is adapted from AndroidX MavenUploadHelper.kt (Apache 2.0) and has a complete attribution header, but THIRD_PARTY_NOTICES.md has no matching entry. Add an entry with Source URL, License name, Copyright, Scope, and full license text.
Comment on lines +1 to +17

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Missing THIRD_PARTY_NOTICES.md entry

build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt — This file is adapted from AndroidX MavenUploadHelper (Apache 2.0, Copyright 2018 The Android Open Source Project) and has a complete attribution header, but there is no matching entry in THIRD_PARTY_NOTICES.md. Add an entry with Source URL, License name, Copyright, Scope, and full license text.

Evidence
  • File header lines 1–17 state Adapted from androidx MavenUploadHelper, Copyright 2018 The Android Open Source Project, and Apache License 2.0 with source URL.
  • Grep of THIRD_PARTY_NOTICES.md for AarTypes, MavenUploadHelper, and the androidx MavenUploadHelper path returns no matching entry.
  • Existing AOSP NOTICES entries cover Base64, Thread Dump Parsing, and Jetpack Compose UI only — not this Maven POM aar-type helper.
  • assignAarTypes() is live code called from SentryPublishPlugin.kt.

Identified by Warden · check-code-attribution · JAJ-FF6


package io.sentry.gradle

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

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")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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")
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
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861
// and do it ourselves
configure(JavaLibrary(JavadocJar.None(), sourcesJar = true))
}

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

// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
extensions.configure<PublishingExtension> {
repositories.maven {
name = "unityMaven"
url = isolated.rootProject.projectDirectory.dir("build${sep}unityMaven").asFile.toURI()
}
}
}
142 changes: 1 addition & 141 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
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 All @@ -12,13 +7,12 @@ plugins {
alias(libs.plugins.detekt)
`maven-publish`
alias(libs.plugins.binary.compatibility.validator)
alias(libs.plugins.vanniktech.maven.publish) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.spring) apply false
alias(libs.plugins.buildconfig) apply false
// dokka is required by gradle-maven-publish-plugin.
// dokka is applied directly by sentry-compose; pinned here so it is on the classpath.
alias(libs.plugins.dokka) apply false
alias(libs.plugins.dokka.javadoc) apply false
alias(libs.plugins.kotlin.compose) apply false
Expand Down Expand Up @@ -113,90 +107,6 @@ allprojects {
}
}

subprojects {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im crying right now because this is so beautiful

apply { plugin("io.sentry.spotless") }
apply { plugin("io.sentry.jdk-target") }

plugins.withId(Config.QualityPlugins.detektPlugin) {
configure<DetektExtension> {
buildUponDefaultConfig = true
allRules = true
config.setFrom("${rootProject.rootDir}/detekt.yml")
baseline = file("detekt-baseline.xml")
}
}

if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-system-test-support" && this.name != "sentry-test-support") {
apply<DistributionPlugin>()
apply<com.vanniktech.maven.publish.MavenPublishPlugin>()

val sep = File.separator

configure<DistributionContainer> {
if (this@subprojects.name.contains("-compose")) {
this.configureForMultiplatform(this@subprojects)
} else {
this.configureForJvm(this@subprojects)
}
// craft only uses zip archives
this.forEach { dist ->
if (dist.name == DistributionPlugin.MAIN_DISTRIBUTION_NAME) {
tasks.named("distTar").configure { enabled = false }
} else {
tasks.named(dist.name + "DistTar").configure { enabled = false }
}
}
}

tasks.named("distZip").configure {
this.dependsOn("publishToMavenLocal")
val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile
this.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")
}
}

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

configure<JavaPluginExtension> {
withJavadocJar()
}
}

apply<MavenPublishPlugin>()

afterEvaluate {
configure<MavenPublishBaseExtension> {
assignAarTypes()
}

// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
configure<PublishingExtension> {
repositories {
maven {
name = "unityMaven"
url = rootProject.layout.buildDirectory.file("unityMaven").get().asFile.toURI()
}
}
}

// maven central info go to:
// ~/.gradle/gradle.properties

// maven central info:
// mavenCentralUsername=user name
// mavenCentralPassword=password
}
}
}

tasks.register("buildForCodeQL") {
subprojects
.filter {
Expand All @@ -217,53 +127,3 @@ tasks.register("buildForCodeQL") {
}
}
}

/*
* 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
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 Config.BuildScript.androidLibs) {
dep.appendNode("type", "aar")
} else if ("$groupValue:$artifactIdValue" in Config.BuildScript.androidXLibs) {
dep.appendNode("type", "aar")
}
}
}
}
}
Loading
Loading