Skip to content
Open
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
2 changes: 1 addition & 1 deletion .cursor/rules/api.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Public API surface, binary compatibility, and common classes to mod

## API Compatibility

Public API is tracked via `.api` files generated by the [Binary Compatibility Validator](https://github.com/Kotlin/binary-compatibility-validator) Gradle plugin. Each module has its own file at `<module>/api/<module>.api`.
Public API is tracked via `.api` files generated by the [ABI validation](https://kotlinlang.org/docs/gradle-binary-compatibility-validation.html) built into the Kotlin Gradle plugin. Each module has its own file at `<module>/api/<module>.api`.

- **Never edit `.api` files manually.** Run `./gradlew apiDump` to regenerate them.
- `./gradlew check` validates current code against `.api` files and fails on unintended changes.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ or

# Binary compatibility validation

To prevent breaking ABI changes and exposing things we should not, we make use of https://github.com/Kotlin/binary-compatibility-validator. If your change intended to introduce a new public method/property or modify the existing one you can overwrite the API declarations to make CI happy as follows (overwrites them from scratch):
To prevent breaking ABI changes and exposing things we should not, we make use of https://kotlinlang.org/docs/gradle-binary-compatibility-validation.html. If your change intended to introduce a new public method/property or modify the existing one you can overwrite the API declarations to make CI happy as follows (overwrites them from scratch):

```shell
make api
Expand Down
4 changes: 4 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ gradlePlugin {
id = "io.sentry.jdk-target"
implementationClass = "io.sentry.gradle.JdkTargetConvention"
}
register("sentryApiValidation") {
id = "io.sentry.api-validation"
implementationClass = "io.sentry.gradle.SentryApiValidationPlugin"
}
register("sentryAnimalSniffer") {
id = "io.sentry.animalsniffer"
implementationClass = "io.sentry.gradle.SentryAnimalSnifferPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.sentry.gradle

import org.gradle.api.provider.SetProperty

/** Configuration for the `io.sentry.api-validation` convention plugin. */
abstract class ApiValidationExtension {
/**
* Packages that are public to the JVM but not part of the SDK's API, and so are left out of the
* dump. Subpackages are left out too.
*/
abstract val ignoredPackages: SetProperty<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.sentry.gradle

import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.create
import org.jetbrains.kotlin.gradle.dsl.abi.AbiValidationExtension
import org.jetbrains.kotlin.gradle.dsl.abi.AbiValidationMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.abi.AbiValidationVariantSpec
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation

private val KOTLIN_PLUGIN_IDS =
listOf(
"org.jetbrains.kotlin.jvm",
"org.jetbrains.kotlin.android",
"org.jetbrains.kotlin.multiplatform",
)

/**
* Checks the public ABI of a module against the dump checked into its `api` directory, using the
* Kotlin Gradle plugin's own ABI validation. Adds `checkKotlinAbi`, which `check` depends on, and
* `updateKotlinAbi`, which rewrites the dump.
*/
@OptIn(ExperimentalAbiValidation::class)
class SentryApiValidationPlugin : Plugin<Project> {
override fun apply(project: Project) {
val extension = project.extensions.create<ApiValidationExtension>("sentryApiValidation")

// The abiValidation extension only exists once a Kotlin plugin has been applied, and a module
// may list this plugin before that one.
KOTLIN_PLUGIN_IDS.forEach {
project.pluginManager.withPlugin(it) { enable(project, extension) }
}

// Aliases for backwards compat with the old binary-compatibility-validator plugin.

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.

i would remove the backwards compatibility here. having more than one way or doing something is confusing for humans and agents.

project.tasks.register("apiDump") { dependsOn("updateKotlinAbi") }
project.tasks.register("apiCheck") { dependsOn("checkKotlinAbi") }
}

private fun enable(project: Project, extension: ApiValidationExtension) {
val kotlin = project.extensions.getByName("kotlin") as ExtensionAware
val spec: AbiValidationVariantSpec =
when (val abi = kotlin.extensions.getByName("abiValidation")) {
is AbiValidationMultiplatformExtension -> abi.also { it.enabled.set(true) }

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.

sad we can't do this. i bet we could though if this was a .kts file. and just FYI you can write these convention plugins in kts

Suggested change
is AbiValidationMultiplatformExtension -> abi.also { it.enabled.set(true) }
is AbiValidationMultiplatformExtension -> abi.enabled.set(true) }

is AbiValidationExtension -> abi.also { it.enabled.set(true) }
else -> throw GradleException("Unexpected abiValidation extension: ${abi.javaClass.name}")
}
// Lazy, because the module configures the extension after this plugin has been applied.
val ignored = extension.ignoredPackages.map { packages -> packages.map { "$it.**" } }
spec.filters { exclude { byNames.addAll(ignored) } }

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.

can you move this up to line 48 like so?

filters { exclude { byNames.addAll(....) } }

}
}
47 changes: 0 additions & 47 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ plugins {
alias(libs.plugins.spotless) apply false
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
Expand Down Expand Up @@ -47,52 +46,6 @@ buildscript {
}
}

apiValidation {

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.

where was this consumed? was it the root plugin alias(libs.plugins.binary.compatibility.validator) ?

ignoredPackages.addAll(
setOf(
"io.sentry.android.core.internal"
)
)
ignoredProjects.addAll(
listOf(
"sentry-samples-android",
"sentry-samples-console",
"sentry-samples-console-opentelemetry-noagent",
"sentry-samples-jul",
"sentry-samples-log4j2",
"sentry-samples-logback",
"sentry-samples-openfeign",
"sentry-samples-servlet",
"sentry-samples-spring",
"sentry-samples-spring-jakarta",
"sentry-samples-spring-7",
"sentry-samples-spring-boot",
"sentry-samples-spring-boot-opentelemetry",
"sentry-samples-spring-boot-opentelemetry-noagent",
"sentry-samples-spring-boot-jakarta",
"sentry-samples-spring-boot-jakarta-log4j2",
"sentry-samples-spring-boot-jakarta-opentelemetry",
"sentry-samples-spring-boot-jakarta-opentelemetry-noagent",
"sentry-samples-spring-boot-webflux",
"sentry-samples-spring-boot-webflux-jakarta",
"sentry-samples-spring-boot-4",
"sentry-samples-spring-boot-4-log4j2",
"sentry-samples-spring-boot-4-opentelemetry",
"sentry-samples-spring-boot-4-opentelemetry-noagent",
"sentry-samples-spring-boot-4-otlp",
"sentry-samples-spring-boot-4-webflux",
"sentry-samples-ktor-client",
"sentry-uitest-android",
"sentry-uitest-android-critical",
"test-app-size",
"sentry-samples-netflix-dgs",
"sentry-samples-console-otlp",
"sentry-test-support",
"sentry-system-test-support"
)
)
}

allprojects {
group = Config.Sentry.group
version = providers.gradleProperty(Config.Sentry.versionNameProp).get()
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
buildconfig = { id = "com.github.gmazzo.buildconfig", version = "5.6.5" }
dokka = { id = "org.jetbrains.dokka", version = "2.0.0" }
dokka-javadoc = { id = "org.jetbrains.dokka-javadoc", version = "2.0.0" }
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.0" }
errorprone = { id = "net.ltgt.errorprone", version = "5.1.1" }
gradle-versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
Expand Down
3 changes: 3 additions & 0 deletions sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.errorprone)
alias(libs.plugins.gradle.versions)
id("io.sentry.api-validation")
}

android {
Expand Down Expand Up @@ -135,3 +136,5 @@ dependencies {
testRuntimeOnly(libs.androidx.fragment.ktx)
testRuntimeOnly(libs.timber)
}

sentryApiValidation { ignoredPackages.add("io.sentry.android.core.internal") }
1 change: 1 addition & 0 deletions sentry-android-distribution/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("com.android.library")
alias(libs.plugins.kotlin.android)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-fragment/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-navigation3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.android.library")
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradle.versions)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-replay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-sqlite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-android-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-apache-http-client-5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.errorprone)
alias(libs.plugins.gradle.versions)
id("io.sentry.api-validation")
}

kotlin {
Expand Down
1 change: 1 addition & 0 deletions sentry-apollo-3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer.android")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-apollo-4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer.android")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-apollo-5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer.android")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-apollo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer.android")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-async-profiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.dokka.javadoc)
`maven-publish` // necessary for publishMavenLocal task to publish correct artifacts
id("io.sentry.api-validation")
}

kotlin {
Expand Down
1 change: 1 addition & 0 deletions sentry-graphql-22/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-graphql-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-graphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-jcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-jdbc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-jul/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-kafka/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-kotlin-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.detekt)
id("io.sentry.animalsniffer.android")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-ktor-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer.android")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-launchdarkly-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.library")
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradle.versions)
id("io.sentry.api-validation")
}

android {
Expand Down
1 change: 1 addition & 0 deletions sentry-launchdarkly-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
1 change: 1 addition & 0 deletions sentry-log4j2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
id("io.sentry.api-validation")
}

tasks.named<KotlinCompile>("compileKotlin") {
Expand Down
Loading
Loading