{"id":19521795,"url":"https://github.com/smarttoolfactory/static-code-analysis","last_synced_at":"2026-05-13T18:41:27.930Z","repository":{"id":109487456,"uuid":"282440141","full_name":"SmartToolFactory/Static-Code-Analysis","owner":"SmartToolFactory","description":"Playground to test KtLint, Detekt, Git Hooks,  Kotlin DSL","archived":false,"fork":false,"pushed_at":"2020-07-31T06:30:22.000Z","size":212,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T14:11:53.983Z","etag":null,"topics":["detekt-plugin","git-hooks","gradle-kotlin-dsl","ktlint","ktlint-gradle"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SmartToolFactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-25T12:32:12.000Z","updated_at":"2023-09-17T18:08:22.000Z","dependencies_parsed_at":"2023-04-17T06:33:51.125Z","dependency_job_id":null,"html_url":"https://github.com/SmartToolFactory/Static-Code-Analysis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FStatic-Code-Analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FStatic-Code-Analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FStatic-Code-Analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FStatic-Code-Analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmartToolFactory","download_url":"https://codeload.github.com/SmartToolFactory/Static-Code-Analysis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240771907,"owners_count":19854982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["detekt-plugin","git-hooks","gradle-kotlin-dsl","ktlint","ktlint-gradle"],"created_at":"2024-11-11T00:34:58.228Z","updated_at":"2026-05-13T18:41:22.884Z","avatar_url":"https://github.com/SmartToolFactory.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradle Kotlin DSL, ktLint, detekt, Git Hooks Sample\n\n[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)\n[![Kotlin Version](https://img.shields.io/badge/kotlin-1.3.72-blue.svg)](https://kotlinlang.org)\n[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)\n\nSample boiler plate code to implement Kotlin DSL, ktlint, detekt and Git Hooks to app on app, library and dynamic feature module step by step with each commit. Also added git hooks using script below in ```.git\\hooks``` folder with a excutable **pre-commit.sh** to turn simple text to excutable call ```chmod a+x pre-commit```\n\n```\n#!/bin/sh\n\n\necho \"Running static analysis...\"\n\n\n# Inspect code using KtLint, and Detekt\n\n# Run KtLint only\n#./gradlew app:ktlintCheck --daemon\n\n# Format code using KtLint, then run Detekt and KtLint static analysis\n./gradlew app:ktlintFormat app:detekt app:ktlintCheck --daemon\n\nstatus=$?\n\n\nif [ \"$status\" = 0 ] ; then\n\n    echo \"Static analysis found no problems.\"\n\n    exit 0\n\nelse\n\n    echo 1\u003e\u00262 \"Static analysis found violations it could not fix.\"\n\n    exit 1\n\nfi\n```\n\nwhich calls in order\n\n1. ktLint to format code before commit\n2. runs detekt for static code analysis\n3. ktlintCheck to check code,\n\nif after these tasks status is 0 then commit is successul, otherwise you need to check out console for links to your code and fix those errors.\n\n\nSteps taken to migrate to Gradle with Kotlin\n\n* Rename settings.gradle to settings.gradle.kts\n* Rename project level build.gradle to build.gradle.kts\n* Add plugins using the snippet below\n```\nplugins {\n    id(Plugins.KTLINT) version PluginVersion.KTLINT_VERSION\n    id(Plugins.DETEKT) version PluginVersion.DETEKT_VERSION\n}\n```\n\nThen us the snippet below to add **ktlint** and **detekt** to each module used in project\n\n```\nsubprojects {\n\n    // KtLint\n    apply(plugin = Plugins.KTLINT) // Version should be inherited from parent\n\n    // Optionally configure plugin\n    ktlint {\n        debug.set(true)\n    }\n\n    // Detekt\n    apply(plugin = Plugins.DETEKT)\n\n    detekt {\n        config = files(\"${project.rootDir}/config/detekt/detekt.yml\")\n        parallel = true\n\n        reports {\n            xml {\n                enabled = true\n                destination = file(\"${project.rootDir}/build/reports/detekt_report.xml\")\n            }\n            html {\n                enabled = true\n                destination = file(\"${project.rootDir}/build/reports/detekt_report.html\")\n            }\n            txt {\n                enabled = true\n                destination = file(\"${project.rootDir}/build/reports/detekt_report.txt\")\n            }\n        }\n    }\n}\n```\n* Create a **buildSrc** folder and add it's build.gradle.kts with\n```\nplugins {\n    `kotlin-dsl`\n}\n```\nto turn it a dsl folder\n\nCreated [DependencyHandler](buildSrc/src/main/java/extension/DependencyHandlerExtension.kt) extension functions to not repeat adding same dependencies to different modules over and over again\n\nFor instance\n\n```\nfun DependencyHandler.addCoreModuleDependencies() {\n\n    implementation(Deps.KOTLIN)\n    implementation(Deps.ANDROIDX_CORE_KTX)\n\n    // Support and Widgets\n    implementation(Deps.APPCOMPAT)\n    implementation(Deps.MATERIAL)\n    implementation(Deps.CONSTRAINT_LAYOUT)\n    implementation(Deps.RECYCLER_VIEW)\n    implementation(Deps.VIEWPAGER2)\n\n    // Lifecycle, LiveData, ViewModel\n    implementation(Deps.ARCH_LIFECYCLE)\n\n    // Navigation Components\n    implementation(Deps.NAVIGATION_FRAGMENT)\n    implementation(Deps.NAVIGATION_UI)\n    implementation(Deps.NAVIGATION_RUNTIME)\n    implementation(Deps.NAVIGATION_DYNAMIC)\n\n    // Dagger\n    implementation(Deps.DAGGER_HILT_ANDROID)\n    kapt(Deps.DAGGER_HILT_COMPILER)\n\n    // Room\n    implementation(Deps.ROOM_RUNTIME)\n    // For Kotlin use kapt instead of annotationProcessor\n    kapt(Deps.ROOM_COMPILER)\n    // optional - Kotlin Extensions and Coroutines support for Room\n    implementation(Deps.ROOM_KTX)\n    // optional - RxJava support for Room\n    implementation(Deps.ROOM_RXJAVA2)\n\n    // RxJava\n    implementation(Deps.RX_JAVA)\n    // RxAndroid\n    implementation(Deps.RX_ANDRIOD)\n\n    // Coroutines\n    implementation(Deps.COROUTINES_CORE)\n    implementation(Deps.COROUTINES_ANDROID)\n\n    // Retrofit\n    implementation(Deps.RETROFIT)\n    implementation(Deps.RETROFIT_GSON_CONVERTER)\n    implementation(Deps.RETROFIT_RX_JAVA2_ADAPTER)\n    // change base url runtime\n    implementation(Deps.RETROFIT_URL_MANAGER)\n    // Gson\n    implementation(Deps.GSON)\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarttoolfactory%2Fstatic-code-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmarttoolfactory%2Fstatic-code-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarttoolfactory%2Fstatic-code-analysis/lists"}