{"id":19628791,"url":"https://github.com/h908714124/auto-builder","last_synced_at":"2025-07-28T08:08:36.198Z","repository":{"id":69888496,"uuid":"89859767","full_name":"h908714124/auto-builder","owner":"h908714124","description":"Convenience builders for auto-value classes","archived":false,"fork":false,"pushed_at":"2019-08-02T20:20:53.000Z","size":249,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T06:36:04.889Z","etag":null,"topics":["auto-value","builder-pattern","dry","productivity"],"latest_commit_sha":null,"homepage":"","language":"Java","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/h908714124.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,"zenodo":null}},"created_at":"2017-04-30T15:39:42.000Z","updated_at":"2019-08-02T20:14:02.000Z","dependencies_parsed_at":"2023-02-22T09:00:22.646Z","dependency_job_id":null,"html_url":"https://github.com/h908714124/auto-builder","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/h908714124/auto-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h908714124%2Fauto-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h908714124%2Fauto-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h908714124%2Fauto-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h908714124%2Fauto-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h908714124","download_url":"https://codeload.github.com/h908714124/auto-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h908714124%2Fauto-builder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267482004,"owners_count":24094508,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["auto-value","builder-pattern","dry","productivity"],"created_at":"2024-11-11T11:56:50.812Z","updated_at":"2025-07-28T08:08:36.168Z","avatar_url":"https://github.com/h908714124.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"### auto-builder\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.h908714124/auto-builder/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.h908714124/auto-builder)\n\nThe builder pattern is useful because it lets us \"update\" immutable objects.\nHowever the pattern is very repetitive to write and maintain,\nso it might be a good idea to actually generate it.\n\nPlease note that this processor depends on another processor\ncalled [auto-value](https://github.com/google/auto/tree/master/value).\nSee below for the necessary configuration.\n\n#### Quick start\n\nTake the `Animal` class from the \n[auto-value docs](https://github.com/google/auto/blob/master/value/userguide/builders.md),\nand add the auto-builder annotation:\n\n````java\n@AutoBuilder\n@AutoValue\nabstract class Animal {\n  abstract String name();\n  abstract int numberOfLegs();\n\n}\n````\n\nA class `Animal_Builder` will be generated in the same package as `Animal`.\nAn instance of `Animal_Builder` can be obtained in two different ways:\n\n* `Animal_Builder.builder()` returns a builder filled with `null`, `0`, `false` and `Optional.empty()`.\n* If you already have an instance of `Animal`, `Animal_Builder.toBuilder(Animal input)`\ncan be used to create a modified copy.\n\n#### Aliasing the builder methods\n\nIt is often convenient to add these the alias methods `builder` and `toBuilder`\nto `Animal`:\n\n````java\n@AutoBuilder\n@AutoValue\nabstract class Animal {\n  abstract String name();\n  abstract int numberOfLegs();\n\n  static Animal_Builder builder() {\n    return Animal_Builder.builder();\n  }\n\n  Animal_Builder toBuilder() {\n    return Animal_Builder.toBuilder(this);\n  }\n}\n````\n\n#### Usage\n\nGiven the above example, we can create an\nanimal as follows:\n\n````java\nAnimal betty = Animal.builder()\n  .name(\"Betty\")\n  .numberOfLegs(4)\n  .build();\n````\n\nNote that the runtime type of `betty` is `AutoValue_Animal`.\nThis processor is just a convenience to create \"regular\"\nauto-value objects.\n\nUpdating the immutable object `betty` is straightforward:\n\n````java\nAnimal sally = betty.toBuilder()\n  .name(\"Sally\")\n  .build();\n````\n\n#### Internals\n\nThis annotation processor scans the generated class `AutoValue_Animal`,\nrather than `Animal` itself.\nSpecifically, it looks at the constructor of `AutoValue_Animal`\nto figure out what to do.\n\nIf `AutoValue_Animal` can't be found at the end of processing,\nbecause the auto-value processing failed,\nthen auto-builder will not generate anything either.\n\n#### Reducing the garbage collection overhead\n\nSince version 1.5, auto-builder is capable of caching the builder instance.\nThis should in theory reduce the garbage collection overhead\n(I have not measured it, though).\n\nUse `reuseBuilder = true` to make\nthe generated code cache and re-use\nthe same builder instance:\n\n````java\n@AutoBuilder(reuseBuilder = true)\n@AutoValue\nabstract class Animal {\n  // [...]\n}\n````\n\n#### Configuration\n\nThe annotations are in a separate jar.\nThey are not needed at runtime, so the scope can be `optional`\nor `provided`.\n\n````xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.h908714124\u003c/groupId\u003e\n  \u003cartifactId\u003eauto-builder-annotations\u003c/artifactId\u003e\n  \u003cversion\u003e1.0\u003c/version\u003e\n  \u003cscope\u003eprovided\u003c/scope\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.google.auto.value\u003c/groupId\u003e\n  \u003cartifactId\u003eauto-value-annotations\u003c/artifactId\u003e\n  \u003cversion\u003e1.6.5\u003c/version\u003e\n\u003c/dependency\u003e\n````\n\nThe processor itself is only needed on the compiler classpath.\n\n````xml\n\u003cbuild\u003e\n  \u003cplugins\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n      \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n      \u003cversion\u003e3.8.1\u003c/version\u003e\n      \u003cconfiguration\u003e\n        \u003cannotationProcessorPaths\u003e\n          \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.h908714124\u003c/groupId\u003e\n            \u003cartifactId\u003eauto-builder\u003c/artifactId\u003e\n            \u003cversion\u003e${auto-builder.version}\u003c/version\u003e\n          \u003c/dependency\u003e\n          \u003cdependency\u003e\n            \u003cgroupId\u003ecom.google.auto.value\u003c/groupId\u003e\n            \u003cartifactId\u003eauto-value\u003c/artifactId\u003e\n            \u003cversion\u003e1.6.5\u003c/version\u003e\n          \u003c/dependency\u003e\n        \u003c/annotationProcessorPaths\u003e\n      \u003c/configuration\u003e\n    \u003c/plugin\u003e\n  \u003c/plugins\u003e\n\u003c/build\u003e\n````\n\nThe equivalent gradle configuration looks as follows:\n \n````groovy\ndependencies {\n    api \"com.google.auto.value:auto-value-annotations:1.6.5\"\n    implementation \"com.github.h908714124:auto-builder-annotations:1.0\"\n    annotationProcessor \"com.google.auto.value:auto-value:1.6.5\"\n    annotationProcessor \"com.github.h908714124:auto-builder:$autoBuilderVersion\"\n}\n````\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh908714124%2Fauto-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh908714124%2Fauto-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh908714124%2Fauto-builder/lists"}