[#3] Add ktlint

This commit is contained in:
Carter Jernigan 2021-09-17 08:33:27 -04:00 committed by Carter Jernigan
parent 68a9cc7d27
commit 7520e031c8
15 changed files with 141 additions and 27 deletions

View File

@ -0,0 +1,21 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="assemble" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list />
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="assembleAndroidTest" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="assembleAndroidTest" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ktlint" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="ktlint" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@ -6,7 +6,6 @@ import android.os.Handler
import android.os.Looper
import android.os.StrictMode
object StrictModeHelper {
fun enableStrictMode() {

View File

@ -4,7 +4,6 @@ plugins {
`kotlin-dsl`
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
implementation("com.android.tools.build:gradle:${getAndroidGradlePluginVersion()}")

View File

@ -0,0 +1,11 @@
disabled_rules=import-ordering,no-wildcard-imports
# Defines the imports layout. The layout can be composed by the following symbols:
# "*" - wildcard. There must be at least one entry of a single wildcard to match all other imports. Matches anything after a specified symbol/import as well.
# "|" - blank line. Supports only single blank lines between imports. No blank line is allowed in the beginning or end of the layout.
# "^" - alias import, e.g. "^android.*" will match all android alias imports, "^" will match all other alias imports.
# import paths - these can be full paths, e.g. "java.util.List.*" as well as wildcard paths, e.g. "kotlin.**"
# Examples (we use ij_kotlin_imports_layout to set an imports layout for both ktlint and IDEA via a single property):
ij_kotlin_imports_layout=* # alphabetical with capital letters before lower case letters (e.g. Z before a), no blank lines
ij_kotlin_imports_layout=*,java.**,javax.**,kotlin.**,^ # default IntelliJ IDEA style, same as alphabetical, but with "java", "javax", "kotlin" and alias imports in the end of the imports list
ij_kotlin_imports_layout=android.**,|,^org.junit.**,kotlin.io.Closeable.*,|,*,^ # custom imports layout

View File

@ -3,8 +3,8 @@ pluginManager.withPlugin("com.android.application") {
configureBaseExtension()
defaultConfig {
minSdk = (project.property("ANDROID_MIN_SDK_VERSION").toString().toInt())
targetSdk = (project.property("ANDROID_TARGET_SDK_VERSION").toString().toInt())
minSdk = project.property("ANDROID_MIN_SDK_VERSION").toString().toInt()
targetSdk = project.property("ANDROID_TARGET_SDK_VERSION").toString().toInt()
// en_XA and ar_XB are pseudolocales for debugging.
// The rest of the locales provides an explicit list of the languages to keep in the

View File

@ -0,0 +1,34 @@
plugins {
id("java")
}
val ktlint by configurations.creating
dependencies {
ktlint("com.pinterest:ktlint:${project.property("KTLINT_VERSION")}")
}
tasks {
val editorConfigFile = rootProject.file(".editorconfig")
val ktlintArgs = listOf("**/src/**/*.kt", "!**/build/**.kt", "--editorconfig=$editorConfigFile")
register("ktlint", org.gradle.api.tasks.JavaExec::class) {
description = "Check code style with ktlint"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
args = ktlintArgs
}
register("ktlintFormat", org.gradle.api.tasks.JavaExec::class) {
description = "Apply code style formatting with ktlint"
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
args = listOf("-F") + ktlintArgs
}
}
java {
val javaVersion = JavaVersion.toVersion(project.property("ANDROID_JVM_TARGET").toString())
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

View File

@ -14,9 +14,9 @@ buildscript {
}
plugins {
kotlin("jvm")
id("com.github.ben-manes.versions")
id("io.gitlab.arturbosch.detekt")
id("zcash.ktlint-conventions")
}
tasks {

View File

@ -1,7 +1,7 @@
# Architecture
TODO This is a placeholder for describing the app architecture.
## Gradle
* Versions are declared in `gradle.properties`. There's still enough inconsistency in how versions are handled in Gradle, that this is as close as we can get to a universal system. A version catalog is used for dependencies and is configured in `settings.gradle.kts`, but other versions like Gradle Plug-ins, the NDK version, Java version, and Android SDK versions don't fit into the version catalog model and are read directly from the properties
* Much of the Gradle configuration lives in `build-conventions` to prevent repetitive configuration as additional modules are added to the project
* Versions are declared in [gradle.properties](../gradle.properties). There's still enough inconsistency in how versions are handled in Gradle, that this is as close as we can get to a universal system. A version catalog is used for dependencies and is configured in [settings.gradle.kts](../settings.gradle.kts), but other versions like Gradle Plug-ins, the NDK version, Java version, and Android SDK versions don't fit into the version catalog model and are read directly from the properties
* Much of the Gradle configuration lives in [build-conventions](../build-conventions/) to prevent repetitive configuration as additional modules are added to the project
* Build scripts are written in Kotlin, so that a single language is used across build and the app code bases
* Only Gradle, Google, and JetBrains plug-ins are included in the critical path. Third party plug-ins can be used, but they're outside the critical path. For example, the Gradle Versions Plugin could be removed and wouldn't negative impact building, testing, or deploying the app

View File

@ -2,7 +2,7 @@
- Does the contribution reference an existing GitHub issue?
- Are the requirements well defined?
- Does static analysis pass? (e.g. `./gradlew detektAll` and `./gradlew lint`)
- Does static analysis pass? (e.g. `./gradlew detektAll`, `./gradlew lint`, `./gradlew ktlint`)
# Specification:

View File

@ -15,7 +15,7 @@ Start by making sure the command line with Gradle works first, because **all the
1. To simplify installation, use [Oracle's JDK](https://www.oracle.com/java/technologies/javase-jdk16-downloads.html) installer that will place the Java installation in the right place
1. Install Android Studio and the Android SDK
1. Download the [stable release of Android Studio](https://developer.android.com/studio#downloads)
1. TODO: Fill in step-by-step instructions for setting up a new environment and installing the Android SDK from within Android Studio.
1. TODO: Fill in step-by-step instructions for setting up a new environment and installing the Android SDK from within Android Studio
1. Check out the code. _Use the command line (instead of Android Studio) to check out the code. This will ensure that your command line environment is set up correctly and avoids a few pitfalls with trying to use Android Studio directly. Android Studio's built-in git client is not as robust as standalone clients_
1. Compile from the command line
1. Navigate to the repo checkout in a terminal
@ -31,19 +31,22 @@ Start by making sure the command line with Gradle works first, because **all the
2. Deleting the invisible `.idea` in the root directory of the project
3. Relaunch Android Studio
2. Clean the individual Gradle project by running `./gradlew clean` which will purge local build outputs.
3. Run Gradle with the flag `--rerun-tasks` which will effectively disable the build cache by re-running tasks and repopulating the cache. E.g. `./gradlew assemble --rerun-tasks`
3. Run Gradle with the argument `--rerun-tasks` which will effectively disable the build cache by re-running tasks and repopulating the cache. E.g. `./gradlew assemble --rerun-tasks`
4. Reboot your computer, which will ensure that Gradle and Kotlin daemons are completely killed and relaunched
5. Delete the global Gradle cache under `~/.gradle/caches`
## Gradle Tasks
A variety of Gradle tasks are set up within the project, and these tasks are also accessible in Android Studio as run configurations.
`assemble` - Compiles the application
`detektAll` - Performs static analysis with Detekt
`lint` - Performs static analysis with Android lint
`dependencyUpdates` - Checks for available dependency updates
* `assemble` - Compiles the application but does not deploy it
* `assembleAndroidTest` - Compiles the application and tests, but does not deploy the application or run the tests
* `detektAll` - Performs static analysis with Detekt
* `ktlint` - Performs code formatting checks with ktlint
* `lint` - Performs static analysis with Android lint
* `dependencyUpdates` - Checks for available dependency updates
## Gradle Properties
A variety of Gradle properties can be used to configure the build.
### Debug Signing
By default, the application is signed by the developers automatically generated debug signing key. In a team of developers, it may be advantageous to share a debug key so that debug builds can access key-restricted services such as Firebase or Google Maps. For such a setup, the path to a shared debug signing key can be set with the property `ZCASH_DEBUG_KEYSTORE_PATH`.

View File

@ -42,6 +42,7 @@ ANDROID_NDK_VERSION=23.0.7599858
ANDROID_GRADLE_PLUGIN_VERSION=7.0.2
DETEKT_VERSION=1.18.1
GRADLE_VERSIONS_PLUGIN_VERSION=0.38.0
KTLINT_VERSION=0.42.1
ANDROIDX_ACTIVITY_VERSION=1.3.1
ANDROIDX_ANNOTATION_VERSION=1.2.0

View File

@ -51,30 +51,30 @@ dependencyResolutionManagement {
version("java", javaVersion)
// Aliases
alias("androidx-activity").to("androidx.activity:activity-ktx:${androidxActivityVersion}")
alias("androidx-activity").to("androidx.activity:activity-ktx:$androidxActivityVersion")
alias("androidx-activity-compose").to("androidx.activity:activity-compose:$androidxActivityVersion")
alias("androidx-appcompat").to("androidx.appcompat:appcompat:$androidxAppcompatVersion")
alias("androidx-annotation").to("androidx.annotation:annotation:${androidxAnnotationVersion}")
alias("androidx-annotation").to("androidx.annotation:annotation:$androidxAnnotationVersion")
alias("androidx-compose-foundation").to("androidx.compose.foundation:foundation:$androidxComposeVersion")
alias("androidx-compose-material").to("androidx.compose.material:material:$androidxComposeVersion")
alias("androidx-compose-material-icons-core").to("androidx.compose.material:material-icons-core:$androidxComposeVersion")
alias("androidx-compose-tooling").to("androidx.compose.ui:ui-tooling-preview:$androidxComposeVersion")
alias("androidx-compose-ui").to("androidx.compose.ui:ui:$androidxComposeVersion")
alias("androidx-core").to("androidx.core:core-ktx:${androidxCoreVersion}")
alias("androidx-core").to("androidx.core:core-ktx:$androidxCoreVersion")
alias("androidx-viewmodel-compose").to("androidx.activity:activity-compose:$androidxActivityVersion")
alias("google-material").to("com.google.android.material:material:${googleMaterialVersion}")
alias("kotlin").to("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
alias("google-material").to("com.google.android.material:material:$googleMaterialVersion")
alias("kotlin").to("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
alias("kotlinx-coroutines-android").to("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinxCoroutinesVersion")
alias("kotlinx-coroutines-core").to("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
alias("zcash").to("cash.z.ecc.android:zcash-android-sdk:${zcashSdkVersion}")
alias("zcash").to("cash.z.ecc.android:zcash-android-sdk:$zcashSdkVersion")
// Test libraries
alias("androidx-espresso-contrib").to("androidx.test.espresso:espresso-contrib:${androidxEspressoVersion}")
alias("androidx-espresso-core").to("androidx.test.espresso:espresso-core:${androidxEspressoVersion}")
alias("androidx-espresso-intents").to("androidx.test.espresso:espresso-intents:${androidxEspressoVersion}")
alias("androidx-junit").to("androidx.test.ext:junit:${androidxTestJunitVersion}")
alias("androidx-testOrchestrator").to("androidx.test:orchestrator:${androidxTestOrchestratorVersion}")
alias("androidx-uiAutomator").to("androidx.test.uiautomator:uiautomator-v18:${androidxUiAutomatorVersion}")
alias("androidx-espresso-contrib").to("androidx.test.espresso:espresso-contrib:$androidxEspressoVersion")
alias("androidx-espresso-core").to("androidx.test.espresso:espresso-core:$androidxEspressoVersion")
alias("androidx-espresso-intents").to("androidx.test.espresso:espresso-intents:$androidxEspressoVersion")
alias("androidx-junit").to("androidx.test.ext:junit:$androidxTestJunitVersion")
alias("androidx-testOrchestrator").to("androidx.test:orchestrator:$androidxTestOrchestratorVersion")
alias("androidx-uiAutomator").to("androidx.test.uiautomator:uiautomator-v18:$androidxUiAutomatorVersion")
alias("kotlinx-coroutines-test").to("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion")
// Bundles

View File

@ -691,7 +691,7 @@ style:
NestedClassesVisibility:
active: true
NewLineAtEndOfFile:
active: true
active: false
NoTabs:
active: false
ObjectLiteralToLambda: