Skip to content

More accurate spotless config #4499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ root = true

[*]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 140
ij_java_names_count_to_use_import_on_demand = 9999
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL

[*.md]
trim_trailing_whitespace = false

[*.java]
indent_size = 2
charset = utf-8

[*.{kt,kts}]
indent_size = 4
charset = utf-8

[*.xml]
indent_size = 2
8 changes: 6 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
plugins {
`kotlin-dsl`
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
gradlePluginPortal()
}

dependencies {
implementation(libs.spotlessLib)
}
8 changes: 8 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
25 changes: 25 additions & 0 deletions build-logic/src/main/kotlin/io.sentry.spotless.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import com.diffplug.spotless.LineEnding

plugins {
id("com.diffplug.spotless")
}

spotless {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new logic.

lineEndings = LineEnding.UNIX
java {
target("src/*/java/**/*.java")
removeUnusedImports()
googleJavaFormat()
targetExclude("src/**/java/io/sentry/vendor/**")
}
kotlin {
target("src/*/kotlin/**/*.kt", "src/*/java/**/*.kt")
ktfmt().googleStyle()
targetExclude("src/test/java/io/sentry/apollo4/generated/**", "src/test/java/io/sentry/apollo3/adapter/**")
}
kotlinGradle {
target("*.gradle.kts")
ktfmt().googleStyle()
}
}

25 changes: 3 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.diffplug.spotless.LineEnding
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
Expand All @@ -10,7 +9,7 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
`java-library`
alias(libs.plugins.spotless)
alias(libs.plugins.spotless) apply false
jacoco
alias(libs.plugins.detekt)
`maven-publish`
Expand Down Expand Up @@ -105,6 +104,8 @@ allprojects {
}

subprojects {
apply { plugin("io.sentry.spotless") }

val jacocoAndroidModules = listOf(
"sentry-android-core",
"sentry-android-fragment",
Expand Down Expand Up @@ -225,26 +226,6 @@ subprojects {
}
}

spotless {
lineEndings = LineEnding.UNIX
java {
target("**/*.java")
removeUnusedImports()
googleJavaFormat()
targetExclude("**/generated/**", "**/vendor/**", "**/sentry-native/**")
}
kotlin {
target("**/*.kt")
ktlint()
targetExclude("**/sentry-native/**", "**/build/**")
}
kotlinGradle {
target("**/*.kts")
ktlint()
targetExclude("**/sentry-native/**")
}
}

tasks.register("buildForCodeQL") {
subprojects
.filter {
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ springboot3 = "3.5.0"
targetSdk = "34"
compileSdk = "34"
minSdk = "21"
spotless = "7.0.4"

[plugins]
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand All @@ -43,7 +44,7 @@ binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibil
compose-compiler = { id = "org.jetbrains.compose", version.ref = "jetbrainsCompose" }
errorprone = { id = "net.ltgt.errorprone", version = "3.0.1" }
gradle-versions = { id = "com.github.ben-manes.versions", version = "0.42.0" }
spotless = { id = "com.diffplug.spotless", version = "6.11.0" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.8" }
jacoco-android = { id = "com.mxalbert.gradle.jacoco-android", version = "0.2.0" }
kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.3" }
Expand Down Expand Up @@ -121,6 +122,7 @@ servlet-jakarta-api = { module = "jakarta.servlet:jakarta.servlet-api", version
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-jdk14 = { module = "org.slf4j:slf4j-jdk14", version.ref = "slf4j" }
slf4j2-api = { module = "org.slf4j:slf4j-api", version = "2.0.5" }
spotlessLib = { module = "com.diffplug.spotless:com.diffplug.spotless.gradle.plugin", version.ref = "spotless"}
springboot-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "springboot2" }
springboot-starter-graphql = { module = "org.springframework.boot:spring-boot-starter-graphql", version.ref = "springboot2" }
springboot-starter-quartz = { module = "org.springframework.boot:spring-boot-starter-quartz", version.ref = "springboot2" }
Expand Down
172 changes: 83 additions & 89 deletions sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,109 @@ import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.kotlin.config.KotlinCompilerVersion

plugins {
id("com.android.library")
kotlin("android")
jacoco
alias(libs.plugins.jacoco.android)
alias(libs.plugins.errorprone)
alias(libs.plugins.gradle.versions)
id("com.android.library")
kotlin("android")
jacoco
alias(libs.plugins.jacoco.android)
alias(libs.plugins.errorprone)
alias(libs.plugins.gradle.versions)
}

android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "io.sentry.android.core"
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "io.sentry.android.core"

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField("String", "SENTRY_ANDROID_SDK_NAME", "\"${Config.Sentry.SENTRY_ANDROID_SDK_NAME}\"")
buildConfigField(
"String",
"SENTRY_ANDROID_SDK_NAME",
"\"${Config.Sentry.SENTRY_ANDROID_SDK_NAME}\"",
)

// for AGP 4.1
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}
// for AGP 4.1
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

buildTypes {
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
}
buildTypes {
getByName("debug") { consumerProguardFiles("proguard-rules.pro") }
getByName("release") { consumerProguardFiles("proguard-rules.pro") }
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }

testOptions {
animationsDisabled = true
unitTests.apply {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
testOptions {
animationsDisabled = true
unitTests.apply {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
}

lint {
warningsAsErrors = true
checkDependencies = true
lint {
warningsAsErrors = true
checkDependencies = true

// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
checkReleaseBuilds = false
}
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
checkReleaseBuilds = false
}

buildFeatures {
buildConfig = true
}
buildFeatures { buildConfig = true }

// needed because of Kotlin 1.4.x
configurations.all {
resolutionStrategy.force(libs.jetbrains.annotations.get())
}
// needed because of Kotlin 1.4.x
configurations.all { resolutionStrategy.force(libs.jetbrains.annotations.get()) }

androidComponents.beforeVariants {
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
}
androidComponents.beforeVariants {
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
}
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "io.sentry")
}
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "io.sentry")
}
}

dependencies {
api(projects.sentry)
compileOnly(libs.jetbrains.annotations)
compileOnly(libs.nopen.annotations)
compileOnly(projects.sentryAndroidFragment)
compileOnly(projects.sentryAndroidTimber)
compileOnly(projects.sentryAndroidReplay)
compileOnly(projects.sentryCompose)

// lifecycle processor, session tracking
implementation(libs.androidx.lifecycle.common.java8)
implementation(libs.androidx.lifecycle.process)
implementation(libs.androidx.core)

errorprone(libs.errorprone.core)
errorprone(libs.nopen.checker)
errorprone(libs.nullaway)

// tests
testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
testImplementation(libs.roboelectric)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.androidx.core.ktx)
testImplementation(libs.androidx.test.core)
testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.androidx.test.runner)
testImplementation(libs.awaitility.kotlin)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.mockito.inline)
testImplementation(projects.sentryTestSupport)
testImplementation(projects.sentryAndroidFragment)
testImplementation(projects.sentryAndroidTimber)
testImplementation(projects.sentryAndroidReplay)
testImplementation(projects.sentryCompose)
testImplementation(projects.sentryAndroidNdk)
testRuntimeOnly(libs.androidx.compose.ui)
testRuntimeOnly(libs.androidx.fragment.ktx)
testRuntimeOnly(libs.timber)
api(projects.sentry)
compileOnly(libs.jetbrains.annotations)
compileOnly(libs.nopen.annotations)
compileOnly(projects.sentryAndroidFragment)
compileOnly(projects.sentryAndroidTimber)
compileOnly(projects.sentryAndroidReplay)
compileOnly(projects.sentryCompose)

// lifecycle processor, session tracking
implementation(libs.androidx.lifecycle.common.java8)
implementation(libs.androidx.lifecycle.process)
implementation(libs.androidx.core)

errorprone(libs.errorprone.core)
errorprone(libs.nopen.checker)
errorprone(libs.nullaway)

// tests
testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
testImplementation(libs.roboelectric)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.androidx.core.ktx)
testImplementation(libs.androidx.test.core)
testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.androidx.test.runner)
testImplementation(libs.awaitility.kotlin)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.mockito.inline)
testImplementation(projects.sentryTestSupport)
testImplementation(projects.sentryAndroidFragment)
testImplementation(projects.sentryAndroidTimber)
testImplementation(projects.sentryAndroidReplay)
testImplementation(projects.sentryCompose)
testImplementation(projects.sentryAndroidNdk)
testRuntimeOnly(libs.androidx.compose.ui)
testRuntimeOnly(libs.androidx.fragment.ktx)
testRuntimeOnly(libs.timber)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ final class ANRWatchDog extends Thread {
private final ANRListener anrListener;
private final MainLooperHandler uiHandler;
private final ICurrentDateProvider timeProvider;

/** the interval in which we check if there's an ANR, in ms */
private long pollingIntervalMs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ private void setOptionsTags(final @NotNull SentryBaseEvent event) {
}
}
}

// endregion

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class BuildInfoProvider {
public BuildInfoProvider(final @NotNull ILogger logger) {
this.logger = Objects.requireNonNull(logger, "The ILogger object is required.");
}

/**
* Returns the Build.VERSION.SDK_INT
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public final class SentryAndroidOptions extends SentryOptions {
@NotNull
private NdkHandlerStrategy ndkHandlerStrategy =
NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT;

/**
* Enable the Java to NDK Scope sync. The default value for sentry-java is disabled and enabled
* for sentry-android.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public Builder(final @NotNull Context context) {
public Builder(Context context, int themeResId) {
this(context, themeResId, null);
}

/**
* Creates a builder for a {@link SentryUserFeedbackDialog} that uses the default alert dialog
* theme. The {@code configuration} can be used to configure the feedback options for this
Expand Down
Loading
Loading