{"id":24305851,"url":"https://github.com/remal-gradle-plugins/generate-sources","last_synced_at":"2026-05-12T23:33:56.885Z","repository":{"id":270897727,"uuid":"911784685","full_name":"remal-gradle-plugins/generate-sources","owner":"remal-gradle-plugins","description":"Gradle plugin that helps to generate sources","archived":false,"fork":false,"pushed_at":"2026-05-05T13:11:13.000Z","size":670,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-05T15:20:07.835Z","etag":null,"topics":["generate","generate-code","generate-sources","gradle","gradle-plugin","plugin"],"latest_commit_sha":null,"homepage":"","language":"Java","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/remal-gradle-plugins.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-03T21:00:57.000Z","updated_at":"2026-05-05T13:11:51.000Z","dependencies_parsed_at":"2025-01-20T01:19:38.289Z","dependency_job_id":"5ca33f03-6124-4298-a7e6-57d486889211","html_url":"https://github.com/remal-gradle-plugins/generate-sources","commit_stats":null,"previous_names":["remal-gradle-plugins/generate-sources"],"tags_count":9,"template":false,"template_full_name":"remal-gradle-plugins/template","purl":"pkg:github/remal-gradle-plugins/generate-sources","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remal-gradle-plugins%2Fgenerate-sources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remal-gradle-plugins%2Fgenerate-sources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remal-gradle-plugins%2Fgenerate-sources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remal-gradle-plugins%2Fgenerate-sources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remal-gradle-plugins","download_url":"https://codeload.github.com/remal-gradle-plugins/generate-sources/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remal-gradle-plugins%2Fgenerate-sources/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32961785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T23:30:32.555Z","status":"ssl_error","status_checked_at":"2026-05-12T23:30:18.191Z","response_time":102,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["generate","generate-code","generate-sources","gradle","gradle-plugin","plugin"],"created_at":"2025-01-17T02:17:06.467Z","updated_at":"2026-05-12T23:33:56.878Z","avatar_url":"https://github.com/remal-gradle-plugins.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Tested on Java LTS versions from \u003c!--property:java-runtime.min-version--\u003e11\u003c!--/property--\u003e to \u003c!--property:java-runtime.max-version--\u003e26\u003c!--/property--\u003e.**\n\n**Tested on Gradle versions from \u003c!--property:gradle-api.min-version--\u003e7.1\u003c!--/property--\u003e to \u003c!--property:gradle-api.max-version--\u003e9.5.0\u003c!--/property--\u003e.**\n\n# `name.remal.generate-sources` plugin\n\n[![configuration cache: supported from v2](https://img.shields.io/static/v1?label=configuration%20cache\u0026message=supported%20from%20v2\u0026color=success)](https://docs.gradle.org/current/userguide/configuration_cache.html)\n\n\u003c!--plugin-usage:name.remal.generate-sources--\u003e\n```groovy\nplugins {\n    id 'name.remal.generate-sources' version '2.0.5'\n}\n```\n\u003c!--/plugin-usage--\u003e\n\n\u0026nbsp;\n\nThis plugin simplifies sources generation for JVM projects.\nIt helps with registering all the necessary dependencies and makes generated sources visible to an IDE.\n\nBasic configuration looks like this:\n\n```groovy\ngenerateSources {\n  forMainSourceSet {\n    java { /* ... */ } // configure Java sources generation\n    resources { /* ... */ } // configure resources generation\n    groovy { /* ... */ } // configure Groovy sources generation\n  }\n\n  forSourceSet(sourceSets.test) { /* ... */ } // to generate sources for other source sets (`test` in this case)\n}\n```\n\n## Generate Java sources\n\nThis configuration\n\n```groovy\ngenerateSources.forMainSourceSet.java {\n  classFile('pkg', 'Logic') {\n    addStaticImport('java.util.Arrays', 'asList')\n    addImport('java.util.List')\n    block(\"public class ${simpleName}\") {\n      line()\n      suppressWarningsLine('unchecked', 'rawtypes')\n      block('public static List execute()') {\n        line('return asList(')\n        ident {\n          lines(\n            \"\\\"${escapeString('multi\\bline\\nstring')}\\\"\", // `escapeString` will escape Java string\n            '2',\n          )\n        }\n        line(');')\n      }\n      line()\n    }\n  }\n}\n```\n\n... generates `build/generated/generateJava/pkg/Logic.java` file:\n\n```java\npackage pkg;\n\nimport static java.util.Arrays.asList;\n\nimport java.util.List;\n\npublic class Logic {\n\n  @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n  public static List execute() {\n    return asList(\n      \"multi\\bline\\nstring\",\n      2\n    );\n  }\n\n}\n```\n\nThe generated file will be compiled by the `compileJava` task.\n\n## Generate text resources\n\nThis configuration\n\n```groovy\ngenerateSources.forMainSourceSet.resources {\n  textFile('file.txt') {\n    line('This is a text file')\n    line('with many lines')\n  }\n}\n```\n\n... generates `build/generated/generateResources/file.txt` file:\n\n```\nThis is a text file\nwith many lines\n```\n\nThe generated file will be processed by the `processResources` task.\n\nThe delegate object of the `generateSources.forMainSourceSet.resources.textFile {}` closure\nis an extended [`java.io.BufferedWriter`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/BufferedWriter.html) with these additional methods:\n\n* `writeFormat(String format, Object... args)` - creates a string using [`String.format()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#format%28java.lang.String,java.lang.Object...%29) and passes it to the [`write()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Writer.html#write%28java.lang.String%29)\n* `copyFrom(java.io.Reader reader)` - copy the content from the [reader](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Reader.html)\n* `newLine()` - overrides [`java.io.BufferedWriter.newLine()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/BufferedWriter.html#newLine%28%29) by writing a line separator from `.editorconfig` or `\\n` by default (the default implementation writes system line separator that depend on the current OS)\n* `line(String line)` - [`write(line)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/BufferedWriter.html#write%28java.lang.String%29) + `newLine()`\n* `line(String format, Object... args)` - creates a string using [`String.format()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#format%28java.lang.String,java.lang.Object...%29) and passes it to `line()`\n* `line()` - executes `newLine()`\n\nThe goals of the additional methods are to simplify the usage of `java.io.BufferedWriter` (by adding `writeFormat()` and `copyFrom()` methods)\nand to make usage experience consistent with classes generation (by adding `line()` methods).\n\n## Generate binary resources\n\nThis configuration\n\n```groovy\ngenerateSources.forMainSourceSet.resources {\n  binaryFile('file.bin') {\n    write([1, 2, 3] as byte[])\n  }\n}\n```\n\n... generates `build/generated/generateResources/file.bin` file with the content of three bytes: `1`, `2`, and `3`.\n\nThe generated file will be processed by the `processResources` task.\n\nThe delegate object of the `generateSources.forMainSourceSet.resources.binaryFile {}` closure\nis an extended [`java.io.BufferedOutputStream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/BufferedOutputStream.html) with this additional method:\n\n* `copyFrom(java.io.InputStream inputStream)` - copy the content from the [input stream](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStream.html)\n\nThe goal of the additional method is to simplify the usage of [`java.io.BufferedOutputStream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/BufferedOutputStream.html) (by adding `copyFrom()` method).\n\n## Generate Groovy sources\n\nThis configuration\n\n```groovy\ngenerateSources.forMainSourceSet.groovy {\n  classFile('pkg', 'Logic') {\n    addStaticImport('java.util.Arrays', 'asList')\n    addImport('java.util.List')\n    block(\"class ${simpleName}\") {\n      line()\n      suppressWarningsLine('unchecked', 'rawtypes')\n      block('static List execute()') {\n        line('return asList(')\n        ident {\n          lines(\n            \"\\\"${escapeString('multi\\bline\\nstring')}\\\"\", // `escapeString` will escape Groovy string\n            '2,',\n          )\n        }\n        line(')')\n      }\n      line()\n    }\n  }\n}\n```\n\n... generates `build/generated/generateGroovy/pkg/Logic.groovy` file:\n\n```groovy\npackage pkg\n\nimport static java.util.Arrays.asList\n\nclass Logic {\n\n  @SuppressWarnings([\"unchecked\", \"rawtypes\"])\n  static List execute() {\n    return asList(\n      \"multi\\bline\\nstring\",\n      2,\n    )\n  }\n\n}\n```\n\nThe generated file will be compiled by the `compileGroovy` task.\n\n# Migration guide\n\n## Version 1.* to 2.*\n\nThe plugin was fully rewritten. There were no intentions to keep it backward compatible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremal-gradle-plugins%2Fgenerate-sources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremal-gradle-plugins%2Fgenerate-sources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremal-gradle-plugins%2Fgenerate-sources/lists"}