Skip to content

Commit 8818afd

Browse files
authored
Integrate spotless and ktfmt (#849)
* Integrate spotless and ktfmt * Fix gradle config * Run spotless over kts files * Run spotless format * Changelog * Format common module
1 parent 617300e commit 8818afd

230 files changed

Lines changed: 14597 additions & 15513 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Internal
66

77
- Migrate Dependencies to Gradle version catalog ([#712](https://github.com/getsentry/sentry-android-gradle-plugin/pull/712))
8+
- Integrate spotless + ktfmt instead of ktlint ([#849](https://github.com/getsentry/sentry-android-gradle-plugin/pull/849))
89

910
## 5.3.0
1011

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: format clean preMerge stop all
22

33
format:
4-
./gradlew ktlintFormat
4+
./gradlew spotlessApply
55

66
clean:
77
./gradlew clean

build.gradle.kts

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,77 @@
11
plugins {
2-
alias(libs.plugins.kotlin) apply false
3-
alias(libs.plugins.kotlinAndroid) apply false
4-
alias(libs.plugins.kapt) apply false
5-
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP apply false
6-
alias(libs.plugins.androidLibrary) version BuildPluginsVersion.AGP apply false
7-
alias(libs.plugins.ktlint)
2+
alias(libs.plugins.kotlin) apply false
3+
alias(libs.plugins.kotlinAndroid) apply false
4+
alias(libs.plugins.kapt) apply false
5+
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP apply false
6+
alias(libs.plugins.androidLibrary) version BuildPluginsVersion.AGP apply false
7+
alias(libs.plugins.spotless)
88
}
99

1010
allprojects {
11-
repositories {
12-
google()
13-
mavenCentral()
14-
}
15-
}
16-
17-
subprojects {
18-
apply {
19-
plugin("org.jlleitschuh.gradle.ktlint")
20-
}
11+
repositories {
12+
google()
13+
mavenCentral()
14+
}
15+
apply { plugin("com.diffplug.spotless") }
2116

22-
ktlint {
23-
debug.set(false)
24-
verbose.set(true)
25-
android.set(true)
26-
outputToConsole.set(true)
27-
ignoreFailures.set(false)
28-
enableExperimentalRules.set(true)
29-
filter {
30-
exclude("**/generated/**")
31-
include("**/kotlin/**")
17+
if (name != "examples") {
18+
spotless {
19+
if (name != rootProject.name) {
20+
kotlin {
21+
ktfmt(libs.versions.ktfmt.get()).googleStyle()
22+
targetExclude("**/generated/**")
3223
}
24+
}
25+
kotlinGradle {
26+
ktfmt(libs.versions.ktfmt.get()).googleStyle()
27+
targetExclude("**/generated/**")
28+
}
3329
}
30+
}
3431
}
3532

36-
tasks.register("clean", Delete::class.java) {
37-
delete(rootProject.buildDir)
38-
dependsOn(gradle.includedBuild("plugin-build").task(":clean"))
39-
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":clean"))
33+
tasks.withType<Delete>().configureEach {
34+
delete(rootProject.buildDir)
35+
dependsOn(gradle.includedBuild("plugin-build").task(":clean"))
36+
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":clean"))
4037
}
4138

4239
tasks.register("integrationTest") {
43-
group = "verification"
44-
description = "Runs the integration tests"
40+
group = "verification"
41+
description = "Runs the integration tests"
4542

46-
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":publishAllPublicationsToMavenTestRepoRepository"))
47-
dependsOn(gradle.includedBuild("plugin-build").task(":integrationTest"))
43+
dependsOn(
44+
gradle
45+
.includedBuild("sentry-kotlin-compiler-plugin")
46+
.task(":publishAllPublicationsToMavenTestRepoRepository")
47+
)
48+
dependsOn(gradle.includedBuild("plugin-build").task(":integrationTest"))
4849
}
4950

5051
tasks.register("preMerge") {
51-
description = "Runs all the tests/verification tasks on both top level and included build."
52+
description = "Runs all the tests/verification tasks on both top level and included build."
5253

53-
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":check"))
54-
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":publishAllPublicationsToMavenTestRepoRepository"))
54+
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":check"))
55+
dependsOn(
56+
gradle
57+
.includedBuild("sentry-kotlin-compiler-plugin")
58+
.task(":publishAllPublicationsToMavenTestRepoRepository")
59+
)
5560

56-
dependsOn(":examples:android-gradle:check")
57-
dependsOn(":examples:android-gradle-kts:check")
58-
dependsOn(":examples:android-ndk:check")
59-
dependsOn(":examples:android-instrumentation-sample:check")
60-
dependsOn(":examples:android-room-lib:check")
61-
dependsOn(gradle.includedBuild("plugin-build").task(":check"))
61+
dependsOn(":examples:android-gradle:check")
62+
dependsOn(":examples:android-gradle-kts:check")
63+
dependsOn(":examples:android-ndk:check")
64+
dependsOn(":examples:android-instrumentation-sample:check")
65+
dependsOn(":examples:android-room-lib:check")
66+
dependsOn(gradle.includedBuild("plugin-build").task(":check"))
6267
}
6368

64-
tasks.getByName("ktlintFormat") {
65-
dependsOn(gradle.includedBuild("plugin-build").task(":ktlintFormat"))
69+
tasks.getByName("spotlessCheck") {
70+
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":spotlessCheck"))
71+
dependsOn(gradle.includedBuild("plugin-build").task(":spotlessCheck"))
6672
}
6773

68-
tasks.getByName("ktlintCheck") {
69-
dependsOn(gradle.includedBuild("plugin-build").task(":ktlintCheck"))
74+
tasks.getByName("spotlessApply") {
75+
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":spotlessApply"))
76+
dependsOn(gradle.includedBuild("plugin-build").task(":spotlessApply"))
7077
}
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
plugins {
2-
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP
3-
id("io.sentry.android.gradle")
2+
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP
3+
id("io.sentry.android.gradle")
44
}
55

66
android {
7-
compileSdk = LibsVersion.SDK_VERSION
8-
defaultConfig {
9-
minSdk = LibsVersion.MIN_SDK_VERSION
10-
targetSdk = LibsVersion.SDK_VERSION
11-
versionCode = 1
12-
versionName = "1.0"
7+
compileSdk = LibsVersion.SDK_VERSION
8+
defaultConfig {
9+
minSdk = LibsVersion.MIN_SDK_VERSION
10+
targetSdk = LibsVersion.SDK_VERSION
11+
versionCode = 1
12+
versionName = "1.0"
13+
}
14+
buildTypes {
15+
getByName("release") {
16+
isMinifyEnabled = true
17+
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
1318
}
14-
buildTypes {
15-
getByName("release") {
16-
isMinifyEnabled = true
17-
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
18-
}
19-
}
20-
namespace = "com.example.sampleapp"
19+
}
20+
namespace = "com.example.sampleapp"
2121
}
2222

2323
sentry {
24-
autoUploadProguardMapping.set(CI.canAutoUpload())
24+
autoUploadProguardMapping.set(CI.canAutoUpload())
2525

26-
telemetryDsn.set(CI.SENTRY_SDKS_DSN)
27-
tracingInstrumentation {
28-
enabled.set(false)
29-
}
26+
telemetryDsn.set(CI.SENTRY_SDKS_DSN)
27+
tracingInstrumentation { enabled.set(false) }
3028
}
Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,68 @@
11
plugins {
2-
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP
3-
alias(libs.plugins.kotlinAndroid)
4-
alias(libs.plugins.kapt)
5-
id("io.sentry.android.gradle")
2+
alias(libs.plugins.androidApplication) version BuildPluginsVersion.AGP
3+
alias(libs.plugins.kotlinAndroid)
4+
alias(libs.plugins.kapt)
5+
id("io.sentry.android.gradle")
66
}
77

88
// useful for local debugging of the androidx.sqlite lib
9-
// make sure to checkout the lib from https://github.com/androidx/androidx/tree/androidx-main/sqlite/sqlite-framework
9+
// make sure to checkout the lib from
10+
// https://github.com/androidx/androidx/tree/androidx-main/sqlite/sqlite-framework
1011
// configurations.all {
1112
// resolutionStrategy.dependencySubstitution {
1213
// substitute(module("androidx.sqlite:sqlite-framework")).using(project(":sqlite-framework"))
1314
// }
1415
// }
1516

1617
android {
17-
compileSdk = LibsVersion.SDK_VERSION
18-
defaultConfig {
19-
minSdk = LibsVersion.MIN_SDK_VERSION
20-
targetSdk = LibsVersion.SDK_VERSION
21-
versionCode = 1
22-
versionName = "1.0"
18+
compileSdk = LibsVersion.SDK_VERSION
19+
defaultConfig {
20+
minSdk = LibsVersion.MIN_SDK_VERSION
21+
targetSdk = LibsVersion.SDK_VERSION
22+
versionCode = 1
23+
versionName = "1.0"
24+
}
25+
buildTypes {
26+
getByName("release") {
27+
isMinifyEnabled = true
28+
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
29+
signingConfig = signingConfigs.getByName("debug")
2330
}
24-
buildTypes {
25-
getByName("release") {
26-
isMinifyEnabled = true
27-
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
28-
signingConfig = signingConfigs.getByName("debug")
29-
}
31+
}
32+
33+
flavorDimensions += "environment"
34+
// just a random product flavor for compatibility testing against AGP
35+
productFlavors {
36+
create("staging") {
37+
dimension = "environment"
38+
versionNameSuffix = "-staging"
3039
}
31-
32-
flavorDimensions += "environment"
33-
// just a random product flavor for compatibility testing against AGP
34-
productFlavors {
35-
create("staging") {
36-
dimension = "environment"
37-
versionNameSuffix = "-staging"
38-
}
40+
}
41+
42+
signingConfigs {
43+
getByName("debug") {
44+
storeFile = file("debug.keystore")
45+
storePassword = "android"
46+
keyAlias = "androiddebugkey"
47+
keyPassword = "android"
3948
}
49+
}
4050

41-
signingConfigs {
42-
getByName("debug") {
43-
storeFile = file("debug.keystore")
44-
storePassword = "android"
45-
keyAlias = "androiddebugkey"
46-
keyPassword = "android"
47-
}
48-
}
51+
compileOptions {
52+
sourceCompatibility = JavaVersion.VERSION_11
53+
targetCompatibility = JavaVersion.VERSION_11
54+
}
55+
kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() }
56+
namespace = "io.sentry.samples.instrumentation"
4957

50-
compileOptions {
51-
sourceCompatibility = JavaVersion.VERSION_11
52-
targetCompatibility = JavaVersion.VERSION_11
53-
}
54-
kotlinOptions {
55-
jvmTarget = JavaVersion.VERSION_11.toString()
56-
}
57-
namespace = "io.sentry.samples.instrumentation"
58+
buildFeatures { compose = true }
5859

59-
buildFeatures {
60-
compose = true
61-
}
60+
composeOptions { kotlinCompilerExtensionVersion = "1.4.6" }
6261

63-
composeOptions {
64-
kotlinCompilerExtensionVersion = "1.4.6"
65-
}
66-
67-
testOptions.unitTests.isIncludeAndroidResources = true
62+
testOptions.unitTests.isIncludeAndroidResources = true
6863
}
6964

70-
kotlin {
71-
jvmToolchain(11)
72-
}
65+
kotlin { jvmToolchain(11) }
7366

7467
// useful, when we want to modify room-generated classes, and then compile them into .class files
7568
// so room does not re-generate and overwrite our changes
@@ -78,43 +71,41 @@ kotlin {
7871
// }
7972

8073
dependencies {
81-
implementation(libs.sample.androidx.recyclerView)
82-
implementation(libs.sample.androidx.lifecycle)
83-
implementation(libs.sample.androidx.appcompat)
74+
implementation(libs.sample.androidx.recyclerView)
75+
implementation(libs.sample.androidx.lifecycle)
76+
implementation(libs.sample.androidx.appcompat)
8477

85-
implementation(libs.sample.androidx.composeRuntime)
86-
implementation(libs.sample.androidx.composeActivity)
87-
implementation(libs.sample.androidx.composeFoundation)
88-
implementation(libs.sample.androidx.composeFoundationLayout)
89-
implementation(libs.sample.androidx.composeNavigation)
78+
implementation(libs.sample.androidx.composeRuntime)
79+
implementation(libs.sample.androidx.composeActivity)
80+
implementation(libs.sample.androidx.composeFoundation)
81+
implementation(libs.sample.androidx.composeFoundationLayout)
82+
implementation(libs.sample.androidx.composeNavigation)
9083

91-
implementation(libs.sample.coroutines.core)
92-
implementation(libs.sample.coroutines.android)
84+
implementation(libs.sample.coroutines.core)
85+
implementation(libs.sample.coroutines.android)
9386

94-
implementation(libs.sample.room.runtime)
95-
implementation(libs.sample.room.ktx)
96-
implementation(libs.sample.room.rxjava)
87+
implementation(libs.sample.room.runtime)
88+
implementation(libs.sample.room.ktx)
89+
implementation(libs.sample.room.rxjava)
9790

98-
implementation(libs.sample.timber.timber)
99-
implementation(project(":examples:android-room-lib"))
100-
implementation(libs.sample.fragment.fragmentKtx)
91+
implementation(libs.sample.timber.timber)
92+
implementation(project(":examples:android-room-lib"))
93+
implementation(libs.sample.fragment.fragmentKtx)
10194

102-
kapt(libs.sample.room.compiler)
95+
kapt(libs.sample.room.compiler)
10396
}
10497

10598
sentry {
106-
debug.set(true)
107-
autoUploadProguardMapping.set(CI.canAutoUpload())
99+
debug.set(true)
100+
autoUploadProguardMapping.set(CI.canAutoUpload())
108101

109-
includeSourceContext.set(CI.canAutoUpload())
110-
autoUploadSourceContext.set(CI.canAutoUpload())
111-
additionalSourceDirsForSourceContext.set(setOf("src/custom/java"))
102+
includeSourceContext.set(CI.canAutoUpload())
103+
autoUploadSourceContext.set(CI.canAutoUpload())
104+
additionalSourceDirsForSourceContext.set(setOf("src/custom/java"))
112105

113-
org.set("sentry-sdks")
114-
projectName.set("sentry-android")
115-
telemetryDsn.set(CI.SENTRY_SDKS_DSN)
106+
org.set("sentry-sdks")
107+
projectName.set("sentry-android")
108+
telemetryDsn.set(CI.SENTRY_SDKS_DSN)
116109

117-
tracingInstrumentation {
118-
forceInstrumentDependencies.set(true)
119-
}
110+
tracingInstrumentation { forceInstrumentDependencies.set(true) }
120111
}

examples/android-instrumentation-sample/src/main/java/io/sentry/samples/instrumentation/ui/list/TrackAdapter.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class TrackAdapter : RecyclerView.Adapter<TrackAdapter.ViewHolder>() {
6767
val context = holder.row.context
6868
val track = data[holder.bindingAdapterPosition]
6969

70-
/* ktlint-disable experimental:argument-list-wrapping */
7170
AlertDialog.Builder(context)
7271
.setTitle("Choose File API")
7372
.setNegativeButton("Cancel") { dialog, _ -> dialog.dismiss() }
@@ -91,7 +90,6 @@ class TrackAdapter : RecyclerView.Adapter<TrackAdapter.ViewHolder>() {
9190
)
9291
dialog.dismiss()
9392
}.show()
94-
/* ktlint-enable experimental:argument-list-wrapping */
9593
}
9694
}
9795

0 commit comments

Comments
 (0)