{"id":13609762,"url":"https://github.com/getspherelabs/buildable","last_synced_at":"2025-08-21T19:22:10.425Z","repository":{"id":154473091,"uuid":"629906539","full_name":"getspherelabs/buildable","owner":"getspherelabs","description":"Buildable is a code generation tool that automates the creation of mappers, factories, and state classes for Kotlin","archived":false,"fork":false,"pushed_at":"2023-05-14T03:55:59.000Z","size":756,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T20:05:26.503Z","etag":null,"topics":[],"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/getspherelabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-04-19T09:08:34.000Z","updated_at":"2025-03-13T19:53:59.000Z","dependencies_parsed_at":"2024-08-01T19:43:39.791Z","dependency_job_id":"745ed2d3-6ab7-446c-8035-3e927fe230be","html_url":"https://github.com/getspherelabs/buildable","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getspherelabs%2Fbuildable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getspherelabs%2Fbuildable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getspherelabs%2Fbuildable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getspherelabs%2Fbuildable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getspherelabs","download_url":"https://codeload.github.com/getspherelabs/buildable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248084742,"owners_count":21045132,"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":[],"created_at":"2024-08-01T19:01:37.785Z","updated_at":"2025-04-09T18:08:47.578Z","avatar_url":"https://github.com/getspherelabs.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eBuildable\u003c/h1\u003e\u003c/br\u003e\n\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/behzod1996/izoh\"\u003e\u003cimg  alt=\"Buildable Cover\" src=\"https://github.com/getspherelabs/buildable/blob/main/docs/images/cover-buildable.png?raw=true\"/\u003e\u003c/a\u003e \u003cbr\u003e\n\u003c/p\u003e\n\n\u003ca href=\"https://github.com/getspherelabs/buildable/actions/workflows/android.yml\"\u003e\u003cimg alt=\"Build Status\" \n  src=\"https://github.com/getspherelabs/buildable/actions/workflows/android.yml/badge.svg\"/\u003e\u003c/a\u003e\n  \n## Why Buildable?\n\n`@Buildable` is a tool designed for Kotlin that facilitates the generation of code for mappers, factories, and state classes. By automating the creation of these components, Buildable can save developers a significant amount of time and effort,\n\n## Build Types\n\n`@Buildable` provides support for three unique build types.\n\n### Factory\n\nGenerates factory methods for creating instances of classes with complex constructors or dependencies. \n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/behzod1996/izoh\"\u003e\u003cimg  alt=\"Buildable Cover\" src=\"https://github.com/getspherelabs/buildable/blob/main/docs/images/BuildableFactory%20-%20Code%20Usage.png?raw=true\" width=\"760\" /\u003e\u003c/a\u003e \u003cbr\u003e\n\u003c/p\u003e\n\n### Mapper\n\nGenerates mapping functions that facilitate the conversion of data between different data classes. This is particularly useful in situations where you need to map data from API responses to your application's domain models, or between different layers of your application.\n\n\u003cp align=\"center\"\u003e\n\n\u003ca href=\"https://github.com/behzod1996/izoh\"\u003e\u003cimg  alt=\"Buildable Cover\" src=\"https://github.com/getspherelabs/buildable/blob/main/docs/images/BuildableMapper%20-%20Code%20Usage%202.png?raw=true\" width=\"760\" /\u003e\u003c/a\u003e \u003cbr\u003e\n\u003c/p\u003e\n\n### State (Working in Progress)\n\n## Configuring Gradle\n\nIn order to use [KSP (Kotlin Symbol Processing)](https://kotlinlang.org/docs/ksp-quickstart.html) and the [Buildable](https://github.com/getspherelabs/buildable) library into your project, follow the steps below.\n\n### Enable KSP in your module\n\nTo enable KSP in your module, add the KSP plugin as shown below to your module's `build.gradle` file:\n\n\u003cdetails open\u003e\n  \u003csummary\u003eKotlin (KTS)\u003c/summary\u003e\n  \n```kotlin\nplugins {\n    id(\"com.google.devtools.ksp\") version \"1.8.10-1.0.9\"\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eGroovy\u003c/summary\u003e\n\n```kotlin\nplugins {\n    id(\"com.google.devtools.ksp\") version \"1.8.10-1.0.9\"\n}\n```\n\u003c/details\u003e\n\n\u003e **Note**: Make sure your current Kotlin version and [KSP version](https://github.com/google/ksp/releases) is the same.\n\n## Add the Buildable library to your module\n\nAdd the dependency below into your **module**'s `build.gradle` file:\n\n```gradle\ndependencies {\n    // For using @BuildableFactory\n    implementation(\"io.github.behzodhalil:buildable-factory-core:1.1.0\")\n    ksp(\"io.github.behzodhalil:buildable-factory:1.1.0\")\n    \n    // For using @BuildableMapper\n    implementation(\"io.github.behzodhalil:buildable-mapper-core:1.1.0\")\n    ksp(\"io.github.behzodhalil:buildable-mapper:1.1.0\")\n}\n```\n### Add source path (KSP)\n\nTo access generated codes from KSP, you need to set up the source path like the below into your **module**'s `build.gradle` file:\n\n\u003cdetails open\u003e\n  \u003csummary\u003eAndroid Kotlin (KTS)\u003c/summary\u003e\n\n```kotlin\nkotlin {\n  sourceSets.configureEach {\n    kotlin.srcDir(\"$buildDir/generated/ksp/$name/kotlin/\")\n  }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eAndroid Groovy\u003c/summary\u003e\n\n```gradle\nandroid {\n    applicationVariants.all { variant -\u003e\n        kotlin.sourceSets {\n            def name = variant.name\n            getByName(name) {\n                kotlin.srcDir(\"build/generated/ksp/$name/kotlin\")\n            }\n        }\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003ePure Kotlin (KTS)\u003c/summary\u003e\n\n```gradle\nkotlin {\n    sourceSets.main {\n        kotlin.srcDir(\"build/generated/ksp/main/kotlin\")\n    }\n    sourceSets.test {\n        kotlin.srcDir(\"build/generated/ksp/test/kotlin\")\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003ePure Kotlin Groovy\u003c/summary\u003e\n\n```gradle\nkotlin {\n    sourceSets {\n        main.kotlin.srcDirs += 'build/generated/ksp/main/kotlin'\n        test.kotlin.srcDirs += 'build/generated/ksp/test/kotlin'\n    }\n}\n```\n\u003c/details\u003e\n\n## Usage and Examples\n\n\u003e **Note**: In order to use the generated code, you need to execute the `./gradlew kspDebugKotlin` command or perform a project rebuild. \n\n### BuildableFactory\n\n`@BuildableFactory` annotation aims to simplify code generation associated with the Factory Method pattern. This simplifies the management of object creation, ultimately enhancing maintainability and code readability.\n- `@BuildableComponent` annotation is utilized to specify the type for creating a factory pattern implementation.\n\n```kotlin\n@BuildableFactory\ninterface Car {\n  fun drive()\n}\n\n@BuildableComponent\nclass Nexia : Car {\n  override fun drive() {\n    println(\"Nexia is driving...\")\n  }\n}\n\n@BuildableComponent\nclass Matiz : Car {\n  override fun drive() {\n    println(\"Matiz is driving...\")\n  }\n```\n\nThe example codes generate `CarFactory` and `CarTypes` for easier object management.\n\n**CarFactory (generated)**:\n```kotlin\npublic enum class CarType {\n  NEXIA,\n  MATIZ,\n}\n\npublic fun CarFactory(key: CarType): Car = when (key) {\n  CarType.NEXIA -\u003e Nexia()\n  CarType.MATIZ -\u003e Matiz()\n}\n```\n\n### BuildableMapper\n\n `@BuildableMapper` annotation is designed to streamline code generation for mapping one class to another, making object creation management more efficient and improving overall maintainability and readability within the codebase.\n\n```kotlin\n@BuildableMapper(\n  from = [NotificationDto::class],\n  to = [NotificationEntity::class]\n)\ndata class NotificationDto(\n  val name: String\n)\n\ndata class NotificationEntity(\n  val name: String\n)\n```\n\nThe example codes generate `NotificationDtoBuildableMapperExtensions.kt` for easier object management.\n\n```kotlin\nfun NotificationEntity.toNotificationDto() = NotificationDto(\n\tname = this.name,\n)\n\nfun NotificationDto.toNotificationEntity() = NotificationEntity(\n\tname = this.name,\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetspherelabs%2Fbuildable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetspherelabs%2Fbuildable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetspherelabs%2Fbuildable/lists"}