openrewrite / openrewrite/rewrite
Gradle Best Practices
Open
Nobody has claimed this yet.
enhancement
gradle
recipe
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
Description
Gradle has now published a list of best practices. Several of these are already covered with existing recipes, but it would be good to improve the recipe coverage for aspects that are missing.
General Best Practices
- Use Kotlin DSL (build.gradle.kts over build.gradle) - https://docs.gradle.org/current/userguide/best_practices_general.html#use_kotlin_dsl
- Use the latest minor version of Gradle - https://docs.gradle.org/current/userguide/best_practices_general.html#use_the_latest_minor_version_of_gradle
- Apply plugins using the plugins block instead of buildscript classpath - https://docs.gradle.org/current/userguide/best_practices_general.html#apply_plugins_using_the_plugins_block
- Do not use internal Gradle APIs - https://docs.gradle.org/current/userguide/best_practices_general.html#do_not_use_internal_apis
- Set build flags in gradle.properties instead of command-line arguments - https://docs.gradle.org/current/userguide/best_practices_general.html#set_build_flags_in_gradle_properties
- Name your root project in settings.gradle(.kts) - https://docs.gradle.org/current/userguide/best_practices_general.html#name_your_root_project
- Do not use gradle.properties in subprojects - https://docs.gradle.org/current/userguide/best_practices_general.html#do_not_use_gradle_properties_in_subprojects
Dependencies Best Practices
- Use version catalogs to centralize dependency versions - https://docs.gradle.org/current/userguide/best_practices_dependencies.html#use_version_catalogs_to_centralize_dependency_versions
- Name version catalog entries appropriately (dashes as separators, camelCase for internal dashes) - https://docs.gradle.org/current/userguide/best_practices_dependencies.html#name_version_catalog_entries_appropriately
- Set up dependency repositories in the settings file - https://docs.gradle.org/current/userguide/best_practices_dependencies.html#set_up_dependency_repositories_in_the_settings_file
- Don't explicitly depend on the Kotlin standard library - https://docs.gradle.org/current/userguide/best_practices_dependencies.html#dont_explicitly_depend_on_the_kotlin_standard_library
- Avoid redundant dependency declarations - https://docs.gradle.org/current/userguide/best_practices_dependencies.html#avoid_redundant_dependency_declarations
- Declare dependencies using single GAV string notation - https://docs.gradle.org/current/userguide/best_practices_dependencies.html#declare_dependencies_using_single_gav_string_notation
Tasks Best Practices
- Avoid dependsOn - use task inputs/outputs instead (already covered by https://github.com/openrewrite/rewrite/issues/5333) - https://docs.gradle.org/current/userguide/best_practices_tasks.html#avoid_dependson
- Favor cacheability annotations (@CacheableTask) over cacheIf()/doNotCacheIf() - https://docs.gradle.org/current/userguide/best_practices_tasks.html#favor_cacheability_annotations
- Group and describe custom tasks - https://docs.gradle.org/current/userguide/best_practices_tasks.html#group_and_describe_custom_tasks
Performance Best Practices
- Use UTF-8 file encoding (org.gradle.jvmargs=-Dfile.encoding=UTF-8) - https://docs.gradle.org/current/userguide/best_practices_performance.html#use_utf_8_file_encoding
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Gradle best-practices pages linked in the issue and the repository's existing recipe coverage. Check issue #5333 for the already-covered dependsOn item, then identify which remaining practices have no recipe. Done means adding focused coverage for agreed missing practices without duplicating existing recipes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100