{"id":21242203,"url":"https://github.com/bitspittle/issue-ksp-gradle-cycle","last_synced_at":"2025-03-15T04:12:07.171Z","repository":{"id":225238629,"uuid":"765409807","full_name":"bitspittle/issue-ksp-gradle-cycle","owner":"bitspittle","description":"A project which demonstrates how KSP generates a cyclical Gradle error if you try to generate code outside of KSP","archived":false,"fork":false,"pushed_at":"2024-03-13T23:15:23.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T19:48:05.201Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/bitspittle.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}},"created_at":"2024-02-29T21:33:11.000Z","updated_at":"2024-02-29T23:16:38.000Z","dependencies_parsed_at":"2024-03-01T00:27:04.408Z","dependency_job_id":"8f89d901-0074-4a10-b352-f2f2ea0e76a0","html_url":"https://github.com/bitspittle/issue-ksp-gradle-cycle","commit_stats":null,"previous_names":["bitspittle/issue-ksp-gradle-cycle"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitspittle%2Fissue-ksp-gradle-cycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitspittle%2Fissue-ksp-gradle-cycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitspittle%2Fissue-ksp-gradle-cycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitspittle%2Fissue-ksp-gradle-cycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitspittle","download_url":"https://codeload.github.com/bitspittle/issue-ksp-gradle-cycle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243681081,"owners_count":20330155,"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-11-21T00:58:41.895Z","updated_at":"2025-03-15T04:12:07.150Z","avatar_url":"https://github.com/bitspittle.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KSP Circular Dependency Issue\n\nThis project demonstrates the core of an issue we're having in our own real project.\n\n* We have a KSP processor that generates a resource file (here, `\":ksp:processor\"`).\n* We have a Gradle task which depends on the generated resource file in order to\n  create some Kotlin source (here, `\":app\"`'s `build.gradle.kts` file which defines `generateCodeTask`)\n\n## Reproducing the issue\n\nTo see the error for yourself, just run `./gradlew :app:run` in the root directory.\n\nThe error will be something like this:\n```\n* Exception is:\norg.gradle.api.CircularReferenceException: Circular dependency between the following tasks:\n:app:generateCodeTask\n\\--- :app:kspKotlin\n     \\--- :app:generateCodeTask\n```\n\n## Points of interest\n\n### `GreetingResourceSymbolProcessor.kt`\n\nCreates a `Greeting.txt` file in\n`/app/build/generated/ksp/main/resources/org/example/ksp/`\n\n---\n\n### `/app/build.gradle.kts`\n\nDefines a task `generateCodeTask` which depends on the generated resource file.\n\nNote that we have to do a strange invocation to pull the resource out of the KSP task:\n\n```kotlin\nval inputFile = tasks.named(\"kspKotlin\").map { kspTask -\u003e\n    RegularFile {\n        kspTask.outputs.files.asFileTree.matching { include(\"**/Greeting.txt\") }.singleFile\n    }\n}\n```\n\nMaybe there's a better way, but this was the best we could find after hours of experimentation.\n\n## Current Fix\n\nTo fix the issue, search the `build.gradle.kts` file for the string \"To fix\". Basically you need to comment out one way\nand uncomment another. This solution came from our Slack discussion, but it will be going away in K2:\n\n```kotlin\n// Before\nkotlin {\n    sourceSets.main {\n        kotlin.srcDir(generateCodeTask)\n    }\n}\n\n// After\ntasks.named\u003cKotlinJvmCompile\u003e(\"compileKotlin\") {\n    source(generateCodeTask)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitspittle%2Fissue-ksp-gradle-cycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitspittle%2Fissue-ksp-gradle-cycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitspittle%2Fissue-ksp-gradle-cycle/lists"}