Skip to content
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

integrate spotless and ktfmt #749

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Fixes

- Fix plugin for spring-dependency-management 1.1.6 ([#741](https://github.com/getsentry/sentry-android-gradle-plugin/pull/741))
- Make `SentryUploadNativeSymbolsTask` configuration-cache compatible ([#747](https://github.com/getsentry/sentry-android-gradle-plugin/pull/747))
- Fix `permission denied` error when extracting sentry-cli concurrently ([#748](https://github.com/getsentry/sentry-android-gradle-plugin/pull/748))

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: format clean preMerge stop all

format:
./gradlew ktlintFormat
./gradlew spotlessApply

clean:
./gradlew clean
Expand Down
36 changes: 19 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
kotlin("jvm") version BuildPluginsVersion.KOTLIN apply false
id("com.android.application") version BuildPluginsVersion.AGP apply false
id("org.jlleitschuh.gradle.ktlint") version BuildPluginsVersion.KTLINT
id("com.diffplug.spotless") version BuildPluginsVersion.SPOTLESS
}

allprojects {
Expand All @@ -13,24 +13,24 @@ allprojects {

subprojects {
apply {
plugin("org.jlleitschuh.gradle.ktlint")
plugin("com.diffplug.spotless")
}

ktlint {
debug.set(false)
verbose.set(true)
android.set(true)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
if (name != "examples") {
spotless {
kotlin {
ktfmt(BuildPluginsVersion.KTFMT).googleStyle()
targetExclude("**/generated/**")
}
kotlinGradle {
ktfmt(BuildPluginsVersion.KTFMT).googleStyle()
targetExclude("**/generated/**")
}
}
}
}

tasks.register("clean", Delete::class.java) {
tasks.withType<Delete>().configureEach {
delete(rootProject.buildDir)
dependsOn(gradle.includedBuild("plugin-build").task(":clean"))
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":clean"))
Expand Down Expand Up @@ -58,10 +58,12 @@ tasks.register("preMerge") {
dependsOn(gradle.includedBuild("plugin-build").task(":check"))
}

tasks.getByName("ktlintFormat") {
dependsOn(gradle.includedBuild("plugin-build").task(":ktlintFormat"))
tasks.getByName("spotlessCheck") {
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":spotlessCheck"))
dependsOn(gradle.includedBuild("plugin-build").task(":spotlessCheck"))
}

tasks.getByName("ktlintCheck") {
dependsOn(gradle.includedBuild("plugin-build").task(":ktlintCheck"))
tasks.getByName("spotlessApply") {
dependsOn(gradle.includedBuild("sentry-kotlin-compiler-plugin").task(":spotlessApply"))
dependsOn(gradle.includedBuild("plugin-build").task(":spotlessApply"))
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ object BuildPluginsVersion {
const val DOKKA = "1.8.10"
const val KOTLIN = "1.8.20"
const val AAR_2_JAR = "0.6"
const val KTLINT = "10.2.1"
const val SPOTLESS = "7.0.0.BETA1"
const val KTFMT = "0.51"
const val SHADOW = "7.1.2"
// do not upgrade to 0.18.0, it does not generate the pom-default.xml and module.json under
// build/publications/maven
Expand Down
38 changes: 18 additions & 20 deletions examples/android-gradle-kts/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
plugins {
id("com.android.application")
id("io.sentry.android.gradle")
id("com.android.application")
id("io.sentry.android.gradle")
}

android {
compileSdk = LibsVersion.SDK_VERSION
defaultConfig {
minSdk = LibsVersion.MIN_SDK_VERSION
targetSdk = LibsVersion.SDK_VERSION
versionCode = 1
versionName = "1.0"
compileSdk = LibsVersion.SDK_VERSION
defaultConfig {
minSdk = LibsVersion.MIN_SDK_VERSION
targetSdk = LibsVersion.SDK_VERSION
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
}
}
namespace = "com.example.sampleapp"
}
namespace = "com.example.sampleapp"
}

sentry {
autoUploadProguardMapping.set(CI.canAutoUpload())
autoUploadProguardMapping.set(CI.canAutoUpload())

telemetryDsn.set(CI.SENTRY_SDKS_DSN)
tracingInstrumentation {
enabled.set(false)
}
telemetryDsn.set(CI.SENTRY_SDKS_DSN)
tracingInstrumentation { enabled.set(false) }
}
151 changes: 71 additions & 80 deletions examples/android-instrumentation-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,75 +1,68 @@
plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
id("io.sentry.android.gradle")
id("com.android.application")
kotlin("android")
kotlin("kapt")
id("io.sentry.android.gradle")
}

// useful for local debugging of the androidx.sqlite lib
// make sure to checkout the lib from https://github.com/androidx/androidx/tree/androidx-main/sqlite/sqlite-framework
// make sure to checkout the lib from
// https://github.com/androidx/androidx/tree/androidx-main/sqlite/sqlite-framework
// configurations.all {
// resolutionStrategy.dependencySubstitution {
// substitute(module("androidx.sqlite:sqlite-framework")).using(project(":sqlite-framework"))
// }
// }

android {
compileSdk = LibsVersion.SDK_VERSION
defaultConfig {
minSdk = LibsVersion.MIN_SDK_VERSION
targetSdk = LibsVersion.SDK_VERSION
versionCode = 1
versionName = "1.0"
compileSdk = LibsVersion.SDK_VERSION
defaultConfig {
minSdk = LibsVersion.MIN_SDK_VERSION
targetSdk = LibsVersion.SDK_VERSION
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
signingConfig = signingConfigs.getByName("debug")
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
proguardFiles.add(getDefaultProguardFile("proguard-android-optimize.txt"))
signingConfig = signingConfigs.getByName("debug")
}
}

flavorDimensions += "environment"
// just a random product flavor for compatibility testing against AGP
productFlavors {
create("staging") {
dimension = "environment"
versionNameSuffix = "-staging"
}

flavorDimensions += "environment"
// just a random product flavor for compatibility testing against AGP
productFlavors {
create("staging") {
dimension = "environment"
versionNameSuffix = "-staging"
}
}

signingConfigs {
getByName("debug") {
storeFile = file("debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}

signingConfigs {
getByName("debug") {
storeFile = file("debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() }
namespace = "io.sentry.samples.instrumentation"

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
namespace = "io.sentry.samples.instrumentation"
buildFeatures { compose = true }

buildFeatures {
compose = true
}
composeOptions { kotlinCompilerExtensionVersion = "1.4.6" }

composeOptions {
kotlinCompilerExtensionVersion = "1.4.6"
}

testOptions.unitTests.isIncludeAndroidResources = true
testOptions.unitTests.isIncludeAndroidResources = true
}

kotlin {
jvmToolchain(11)
}
kotlin { jvmToolchain(11) }

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

dependencies {
implementation(Samples.AndroidX.recyclerView)
implementation(Samples.AndroidX.lifecycle)
implementation(Samples.AndroidX.appcompat)
implementation(Samples.AndroidX.recyclerView)
implementation(Samples.AndroidX.lifecycle)
implementation(Samples.AndroidX.appcompat)

implementation(Samples.AndroidX.composeRuntime)
implementation(Samples.AndroidX.composeActivity)
implementation(Samples.AndroidX.composeFoundation)
implementation(Samples.AndroidX.composeFoundationLayout)
implementation(Samples.AndroidX.composeNavigation)
implementation(Samples.AndroidX.composeRuntime)
implementation(Samples.AndroidX.composeActivity)
implementation(Samples.AndroidX.composeFoundation)
implementation(Samples.AndroidX.composeFoundationLayout)
implementation(Samples.AndroidX.composeNavigation)

implementation(Samples.Coroutines.core)
implementation(Samples.Coroutines.android)
implementation(Samples.Coroutines.core)
implementation(Samples.Coroutines.android)

implementation(Samples.Room.runtime)
implementation(Samples.Room.ktx)
implementation(Samples.Room.rxjava)
implementation(Samples.Room.runtime)
implementation(Samples.Room.ktx)
implementation(Samples.Room.rxjava)

implementation(Samples.Timber.timber)
implementation(Samples.Fragment.fragmentKtx)
implementation(project(":examples:android-room-lib"))
implementation(Samples.Timber.timber)
implementation(Samples.Fragment.fragmentKtx)
implementation(project(":examples:android-room-lib"))

kapt(Samples.Room.compiler)
kapt(Samples.Room.compiler)
}

sentry {
debug.set(true)
autoUploadProguardMapping.set(CI.canAutoUpload())
debug.set(true)
autoUploadProguardMapping.set(CI.canAutoUpload())

includeSourceContext.set(true)
autoUploadSourceContext.set(CI.canAutoUpload())
additionalSourceDirsForSourceContext.set(setOf("src/custom/java"))
includeSourceContext.set(true)
autoUploadSourceContext.set(CI.canAutoUpload())
additionalSourceDirsForSourceContext.set(setOf("src/custom/java"))

org.set("sentry-sdks")
projectName.set("sentry-android")
telemetryDsn.set(CI.SENTRY_SDKS_DSN)
org.set("sentry-sdks")
projectName.set("sentry-android")
telemetryDsn.set(CI.SENTRY_SDKS_DSN)

tracingInstrumentation {
forceInstrumentDependencies.set(true)
}
tracingInstrumentation { forceInstrumentDependencies.set(true) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class TrackAdapter : RecyclerView.Adapter<TrackAdapter.ViewHolder>() {
val context = holder.row.context
val track = data[holder.bindingAdapterPosition]

/* ktlint-disable experimental:argument-list-wrapping */
AlertDialog.Builder(context)
.setTitle("Choose File API")
.setNegativeButton("Cancel") { dialog, _ -> dialog.dismiss() }
Expand All @@ -91,7 +90,6 @@ class TrackAdapter : RecyclerView.Adapter<TrackAdapter.ViewHolder>() {
)
dialog.dismiss()
}.show()
/* ktlint-enable experimental:argument-list-wrapping */
}
}

Expand Down
36 changes: 17 additions & 19 deletions examples/android-room-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
plugins {
id("com.android.library")
kotlin("android")
id("com.android.library")
kotlin("android")
}

android {
compileSdk = LibsVersion.SDK_VERSION
defaultConfig {
minSdk = LibsVersion.MIN_SDK_VERSION
targetSdk = LibsVersion.SDK_VERSION
}
compileSdk = LibsVersion.SDK_VERSION
defaultConfig {
minSdk = LibsVersion.MIN_SDK_VERSION
targetSdk = LibsVersion.SDK_VERSION
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
namespace = "io.sentry.android.instrumentation.lib"
kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() }
namespace = "io.sentry.android.instrumentation.lib"
}

dependencies {
implementation(Samples.Coroutines.core)
implementation(Samples.Coroutines.android)
implementation(Samples.Coroutines.core)
implementation(Samples.Coroutines.android)

implementation(Samples.Room.runtime)
implementation(Samples.Room.ktx)
implementation(Samples.Room.runtime)
implementation(Samples.Room.ktx)

// this is here for test purposes, to ensure that transitive dependencies are also recognized
// by our auto-installation
api(Samples.Retrofit.retrofit)
api(Samples.Retrofit.retrofitGson)
// this is here for test purposes, to ensure that transitive dependencies are also recognized
// by our auto-installation
api(Samples.Retrofit.retrofit)
api(Samples.Retrofit.retrofitGson)
}
Loading
Loading