{"id":16351405,"url":"https://github.com/autonomousapps/gradle-best-practices-plugin","last_synced_at":"2025-03-16T15:31:47.253Z","repository":{"id":60074063,"uuid":"540647630","full_name":"autonomousapps/gradle-best-practices-plugin","owner":"autonomousapps","description":"Gradle Plugin that detects violations of Gradle best practices in Gradle Plugins","archived":false,"fork":false,"pushed_at":"2023-09-18T16:36:09.000Z","size":139,"stargazers_count":184,"open_issues_count":9,"forks_count":3,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-02-27T11:06:23.543Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/autonomousapps.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2022-09-23T23:22:17.000Z","updated_at":"2025-01-21T10:23:14.000Z","dependencies_parsed_at":"2024-10-27T10:58:15.178Z","dependency_job_id":"735e1994-13d0-4642-b713-c1bc91d4297d","html_url":"https://github.com/autonomousapps/gradle-best-practices-plugin","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomousapps%2Fgradle-best-practices-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomousapps%2Fgradle-best-practices-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomousapps%2Fgradle-best-practices-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autonomousapps%2Fgradle-best-practices-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autonomousapps","download_url":"https://codeload.github.com/autonomousapps/gradle-best-practices-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822312,"owners_count":20353496,"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-10-11T01:09:20.455Z","updated_at":"2025-03-16T15:31:46.995Z","avatar_url":"https://github.com/autonomousapps.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradle Best Practices Plugin\n\n## Add to your project\n\n```gradle\n// build.gradle[.kts]\nplugins {\n  id(\"com.autonomousapps.plugin-best-practices-plugin\") version \"\u003c\u003clatest version\u003e\u003e\"\n}\n```\n\n## Use it\n\n```shell\n./gradlew :plugin:checkBestPractices\n```\n\nWhere `:plugin` is the name of your plugin project.\n\nOr, since the `checkBestPractices` task is automatically added as a dependency of the `check` task:\n\n```shell\n./gradlew :plugin:check\n```\n\n## Example results\n\nThe `checkBestPractices` task may print a report such as the following:\n\n```groovy\ncom.test.GreetingPlugin#apply(Ljava.lang.Object;)V -\u003e\n  com.test.GreetingPlugin#apply(Lorg.gradle.api.Project;)V -\u003e\n  org.gradle.api.Project#allprojects(Lorg.gradle.api.Action;)V\n\ncom.test.FancyTask#action()V -\u003e\n  com.test.FancyTask#doAction()V -\u003e\n  com.test.FancyTask$ReallyFancyTask#doAction()V -\u003e\n  com.test.FancyTask$ReallyFancyTask#getProject()Lorg.gradle.api.Project;\n```\n\nThis indicates that your plugin is calling `Project#allprojects()`, which violates best practices no matter the context;\nand also that it calls `Task#getProject()`, which violates best practices when called from the context of a method\nannotated with `@TaskAction`.\n\n## Baselines\n\nIn case there are many best practice violations in a project, it's worth generating a baseline to temporarily accept issues, and to prevent new ones from getting onto the main branch.\n\nTo generate a baseline run the `bestPracticesBaseline` task:\n```shell\n./gradlew :plugin:bestPracticesBaseline\n```\n\nThis will generate a file called: `best-practices-baseline.json` in the project directory.\nVersion control this file, so gets propagated to CI and every developer.\nFuture executions of `checkBestPractices` task will take this baseline into account and won't fail on recorded violations.\n\n## Summary of issues currently detected\n\n### Instances of cross-project configuration\n\nThis is dangerous for a variety of reasons. It defeats configuration on demand and will be impermissible in the future\nwhen Gradle implements [project isolation](https://gradle.github.io/configuration-cache/#project_isolation). In the\npresent, these APIs permit mutation of other projects, and this kind of cross-project configuration can easily lead to\nunmaintainable builds.\n\n1. Any usage of `Project#allprojects()`.\n2. Any usage of `Project#getAllprojects()`.\n3. Any usage of `Project#subprojects()`.\n4. Any usage of `Project#getSubprojects()`.\n\n### Usages of a `Project` instance from a task action\n\nThis will break the [configuration cache](https://docs.gradle.org/nightly/userguide/configuration_cache.html), since\n`Project`s cannot be serialized.\n\n1. Usages of `getProject()` in the context of a method annotated with `@TaskAction`. \n\n### Usages of eager APIs instead of lazy ones on the TaskContainer interface\n\nLazy APIs delay the realization of tasks until they're actually required, which avoids doing intensive work \nduring the configuration phase since it can have a large impact on build performance. \nRead more [here](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html#sec:old_vs_new_configuration_api_overview)\n\n1. Any usage of `TaskContainer#all`. Use `configureEach` instead.\n2. Any usage of `TaskContainer#create`. Use `register` instead.\n3. Any usage of `TaskContainer#getByName`. Use `named` instead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautonomousapps%2Fgradle-best-practices-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautonomousapps%2Fgradle-best-practices-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautonomousapps%2Fgradle-best-practices-plugin/lists"}