{"id":13608950,"url":"https://github.com/cortinico/ktfmt-gradle","last_synced_at":"2025-04-04T16:13:43.200Z","repository":{"id":41883998,"uuid":"312611660","full_name":"cortinico/ktfmt-gradle","owner":"cortinico","description":"A Gradle plugin to apply ktfmt to your builds, and reformat you Kotlin source code like a glimpse 🧹🐘","archived":false,"fork":false,"pushed_at":"2024-10-23T21:18:07.000Z","size":817,"stargazers_count":154,"open_issues_count":11,"forks_count":19,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-29T16:57:20.222Z","etag":null,"topics":["formatter","formatting","gradle","gradle-plugin","gradle-plugin-kotlin","hacktoberfest","kotlin","kotlin-android","kotlin-gradle","ktfmt","ktfmt-gradle","lint","linter","reformat"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cortinico.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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-11-13T15:23:07.000Z","updated_at":"2024-10-21T17:22:04.000Z","dependencies_parsed_at":"2023-11-08T02:18:53.152Z","dependency_job_id":"cee6086c-4b64-4721-983a-4a516e9346b8","html_url":"https://github.com/cortinico/ktfmt-gradle","commit_stats":{"total_commits":299,"total_committers":12,"mean_commits":"24.916666666666668","dds":0.3612040133779264,"last_synced_commit":"23b22420f7edbe810a3f8c70e8f8488c0b87eb7f"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":"cortinico/kotlin-gradle-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortinico%2Fktfmt-gradle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortinico%2Fktfmt-gradle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortinico%2Fktfmt-gradle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortinico%2Fktfmt-gradle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cortinico","download_url":"https://codeload.github.com/cortinico/ktfmt-gradle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208140,"owners_count":20901570,"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":["formatter","formatting","gradle","gradle-plugin","gradle-plugin-kotlin","hacktoberfest","kotlin","kotlin-android","kotlin-gradle","ktfmt","ktfmt-gradle","lint","linter","reformat"],"created_at":"2024-08-01T19:01:31.272Z","updated_at":"2025-04-04T16:13:43.174Z","avatar_url":"https://github.com/cortinico.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# ktfmt-gradle 🧹🐘\n\nA wrapper to apply [ktfmt](https://github.com/facebookincubator/ktfmt) to your Gradle builds, and reformat you Kotlin\nsource code like a glimpse.\n\n[![Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/ncorti/ktfmt/gradle/com.ncorti.ktfmt.gradle.gradle.plugin/maven-metadata.xml.svg?label=Gradle%20Plugin%20Portal\u0026colorB=brightgreen\u0026logo=gradle)](https://plugins.gradle.org/plugin/com.ncorti.ktfmt.gradle) [![Pre Merge Checks](https://github.com/cortinico/ktfmt-gradle/workflows/Pre%20Merge%20Checks/badge.svg)](https://github.com/cortinico/ktfmt-gradle/actions?query=workflow%3A%22Pre+Merge+Checks%22) ![Language](https://img.shields.io/github/languages/top/cortinico/kotlin-android-template?color=blue\u0026logo=kotlin) [![License](https://img.shields.io/github/license/cortinico/kotlin-android-template.svg)](LICENSE) [![Use this template](https://img.shields.io/badge/from-kotlin--gradle--plugin--template-brightgreen?logo=dropbox)](https://github.com/cortinico/kotlin-gradle-plugin-template/generate) [![Twitter](https://img.shields.io/badge/Twitter-@cortinico-blue.svg?style=flat\u0026logo=twitter)](http://twitter.com/cortinico)\n\n## How to use 👣\n\n**ktfmt-gradle** is distributed through [Gradle Plugin Portal](https://plugins.gradle.org/). To use it you need to add\nthe following dependency to your gradle files.\n\nPlease note that those code needs to be added the gradle file of the **module** where you want to reformat the code\n(**not the top level** build.gradle[.kts] file).\n\nIf you're using the `plugin{}` blocks in your Gradle file:\n\n```kotlin\nplugins {\n    id(\"com.ncorti.ktfmt.gradle\") version \"\u003clatest_version\u003e\"\n}\n```\n\nIf you're instead using the Groovy Gradle files and the old `buildscript` block:\n\n```groovy\nbuildscript {\n    repositories {\n        maven { url \"https://plugins.gradle.org/m2/\" }\n    }\n\n    dependencies {\n        classpath \"com.ncorti.ktfmt.gradle:plugin:\u003clatest_version\u003e\"\n    }\n}\n\napply plugin: \"com.ncorti.ktfmt.gradle\"\n```\n\n### Requirements\n\nPlease note that `ktfmt-gradle` relies on `ktfmt` hence the minimum supported JDK version is **11**.\n\nPlease also note the following requirements:\n\n* **Android**. `ktfmt-gradle` relies on features from **Android Gradle Plugin 4.1+**. So make sure you bump AGP before applying this plugin.\n\n### Task\n\nBy default, `ktfmt-gradle` will add two Gradle tasks to your build:\n\n- `ktfmtCheck` that will check if the code in your module is ktfmt-compliant\n- `ktfmtFormat` that will reformat your code with ktfmt\n\nThose two tasks will invoke `ktfmt` on the **whole module**. More specific tasks are avialable based on the module type.\n\nAdditionally, the plugin will create check/format tasks for top-level Kotlin script files:\n\n- `ktfmtCheckScripts` that will check if the top-level script files in your module is ktfmt-compliant\n- `ktfmtFormatScripts` that will reformat top-level script files with ktfmt\n\n#### Jvm/Js Modules\n\nFor Jvm/Js modules, the plugin will create a check/format task for **every source set**. For example, jvm modules will\nhave a `ktfmtCheckMain` and `ktfmtCheckTest` tasks for the `main` and `test` source sets.\n\n#### Multiplatform Modules\n\nKotlin Multiplatform modules will have separate tasks for **every target/source set**. You will have tasks\nlike `ktfmtCheckCommonMain` and `ktfmtCheckCommonTest` and so on. If you target also Android, the tasks explained below\nwill be added as well.\n\n#### Android Modules\n\nKotlin Android modules will also have separate tasks for **every source set**. Due to how source sets are handled on\nAndroid, you can expect ktfmt tasks to follow the convention: `ktfmt[Check|Format][SourceSet][Variant]JavaSource`. For\nexample, the `ktfmtCheckAndroidTestDebugJavaSource`.\n\n## Features 🎨\n\n- 100% Kotlin-only plugin.\n- **Parallel** file processing with Kotlin Coroutines.\n- Supports **incremental** builds (i.e. checks tasks won't rerun if source is unchanged).\n- Configurable thanks to the `ktfmt{}` block.\n- Integrated with Jvm/Android/KMM modules.\n\n## Configuring 🛠\n\nYou can configure the behavior of the `ktfmt` invocation with the `ktfmt` block in your `build.gradle.[kts]` file.\n\nTo enable different styles you can simply:\n\n```kotlin\nktfmt {\n    // Google style - 2 space indentation \u0026 automatically adds/removes trailing commas\n    googleStyle()\n    \n    // KotlinLang style - 4 space indentation - From kotlinlang.org/docs/coding-conventions.html\n    kotlinLangStyle()\n}\n```\n\nIf you wish to have further control on the tool you can instead:\n\n```kotlin\nktfmt {\n    // Breaks lines longer than maxWidth. Default 100.\n    maxWidth.set(80)\n    // blockIndent is the indent size used when a new block is opened, in spaces.\n    blockIndent.set(8)\n    // continuationIndent is the indent size used when a line is broken because it's too\n    continuationIndent.set(8)\n    // Whether ktfmt should remove imports that are not used.\n    removeUnusedImports.set(false)\n    // Whether ktfmt should automatically add/remove trailing commas.\n    manageTrailingCommas.set(false)\n}\n```\n\nBy default, sourceSets that are in your `build` folder are ignored. To customize this, you can set a regex pattern to\nexclude certain sourceSets:\n\n```kotlin\nktfmt {\n    srcSetPathExclusionPattern = Regex(\".*generated.*\")\n}\n```\n\nPlease note, that this property will only affect the sourceSet path and not the individual files inside the sourceSet.\nTo include or exclude files inside a sourceSet, use the include and exclude properties of the ktfmt tasks.\n\n## Using with a pre-commit hook 🎣\n\nYou can leverage the `--include-only` to let ktfmt-gradle run only on a specific subset of files.\n\nTo do this you can register a simple task of type `KtfmtCheckTask` or `KtfmtFormatTask` in your `build.gradle.kts` as\nfollows:\n\n```kotlin\nimport com.ncorti.ktfmt.gradle.tasks.*\n\ntasks.register\u003cKtfmtFormatTask\u003e(\"ktfmtPrecommit\") {\n    source = project.fileTree(rootDir)\n    include(\"**/*.kt\")\n}\n```\n\nYou can then invoke the task with `--include-only` and a comma-separated (or colon-separated) list of relative path of\nfiles:\n\n```\n./gradlew ktfmtPrecommit --include-only=src/main/java/File1.kt:src/main/java/File2.kt\n```\n\nThe task will execute only on the file you passed and will skip all the others.\n\n## Contributing 🤝\n\nFeel free to open a issue or submit a pull request for any bugs/improvements.\n\n## License 📄\n\nThis project is licensed under the MIT License - see the [License](License) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortinico%2Fktfmt-gradle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcortinico%2Fktfmt-gradle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortinico%2Fktfmt-gradle/lists"}