Gradle Commands Cheat Sheet

Gradle Commands Cheat Sheet
Gradle Commands Cheat Sheet

Gradle Commands Cheat Sheet

Basic Commands

1. gradle tasks
List all available tasks.

gradle tasks

2. gradle build
Assemble and build the project.

gradle build

3. gradle clean
Remove the build directory.

gradle clean

4. gradle test
Run tests for the project.

gradle test

5. gradle assemble
Assemble the outputs of the project.

gradle assemble

6. gradle check
Run all verification tasks (e.g., tests).

gradle check

7. gradle run
Run the main class.

gradle run

8. gradle javadoc
Generate Javadoc API documentation.

gradle javadoc

9. gradle tasks --all
List all tasks including those from plugins.

gradle tasks --all

10. gradle dependencies
Display the project’s dependencies.

gradle dependencies

Project Configuration

11. gradle init
Initialize a new Gradle project.

gradle init

12. gradle wrapper
Generate Gradle wrapper files.

gradle wrapper

13. gradle properties
Display the properties of the project.

gradle properties

14. gradle version
Display the Gradle version.

gradle version

15. gradle --stop
Stop the Gradle daemon.

gradle --stop

16. gradle --daemon
Run Gradle as a daemon.

gradle build --daemon

17. gradle build --no-daemon
Run Gradle without the daemon.

gradle build --no-daemon

18. gradle help
Show help for a specific task.

gradle help --task <taskName>

19. gradle build --console=plain
Use plain console output.

gradle build --console=plain

20. gradle build --info
Display more logging information.

gradle build --info

Dependency Management

21. gradle dependencies --configuration <configuration>
Display dependencies for a specific configuration.

gradle dependencies --configuration runtimeClasspath

22. gradle dependencyInsight --dependency <dependency>
Display insight into a specific dependency.

gradle dependencyInsight --dependency junit

23. gradle build --refresh-dependencies
Refresh dependencies.

gradle build --refresh-dependencies

24. gradle resolve
Resolve dependencies (not commonly used).

gradle resolve

25. gradle publish
Publish the build artifacts to a repository.

gradle publish

26. gradle dependencies --exclude <group>:<module>
Exclude a dependency.

gradle dependencies --exclude org.springframework:spring-core

27. gradle dependencyInsight --configuration <configuration>
Insight into a dependency for a specific configuration.

gradle dependencyInsight --configuration compileClasspath

28. gradle dependencyReport
Generate a dependency report (deprecated).

gradle dependencyReport

29. gradle publishToMavenLocal
Publish artifacts to the local Maven repository.

gradle publishToMavenLocal

30. gradle generatePomFileForMavenJavaPublication
Generate a POM file for Maven publication.

gradle generatePomFileForMavenJavaPublication

Build Configuration

31. gradle build -x test
Exclude tests from the build.

gradle build -x test

32. gradle build --parallel
Run tasks in parallel.

gradle build --parallel

33. gradle build --max-workers=<number>
Set the maximum number of workers.

gradle build --max-workers=4

34. gradle build --continue
Continue building even if some tasks fail.

gradle build --continue

35. gradle build --profile
Create a build profile report.

gradle build --profile

36. gradle build --scan
Create a build scan (requires Gradle Enterprise).

gradle build --scan

37. gradle build --debug
Display debug logging.

gradle build --debug

38. gradle build --quiet
Run with minimal output.

gradle build --quiet

39. gradle build --stacktrace
Show full stack traces for failures.

gradle build --stacktrace

40. gradle build --no-daemon
Run without the Gradle daemon.

gradle build --no-daemon

Running Specific Tasks

41. gradle
Run a specific task.

gradle test

42. gradle --info
Run a task with info logging.

gradle test --info

43. gradle --debug
Run a task with debug logging.

gradle test --debug

44. gradle --stacktrace
Run a task and show stacktrace for errors.

gradle test --stacktrace

45. gradle --no-daemon
Run a task without the Gradle daemon.

gradle test --no-daemon

46. gradle --offline
Run a task in offline mode.

gradle test --offline

47. gradle --continue
Run a task and continue if some tasks fail.

gradle test --continue

48. gradle --configure-on-demand
Configure a task on demand.

gradle test --configure-on-demand

49. gradle --no-rebuild
Run a task without rebuilding.

gradle test --no-rebuild

50. gradle --build-cache
Use the build cache.

gradle test --build-cache

Advanced Commands

51. gradle build --scan
Generate a build scan report.

gradle build --scan

52. gradle build --no-build-cache
Run the build without using the build cache.

gradle build --no-build-cache

53. gradle build --configure-on-demand
Configure projects on demand.

gradle build --configure-on-demand

54. gradle build --offline
Run the build offline.

gradle build --offline

55. gradle build --no-configuration-cache
Run the build without using configuration cache.

gradle build --no-configuration-cache

56. gradle build --build-cache
Run the build with build cache.

gradle build --build-cache

57. gradle build --rebuild
Rebuild the project from scratch.

gradle build --rebuild

58. gradle build --exclude-task <task>
Exclude a specific task from the build.

gradle build --exclude-task test

59. gradle build --project-cache
Use project cache.

gradle build --project-cache

60. gradle build --continue
Continue building even if some tasks fail.

gradle build --continue

Testing

61. gradle test --tests <testClass>
Run tests in a specific class.

gradle test --tests com.example.MyTest

62. gradle test --tests <testClass>.<testMethod>
Run a specific test method.

gradle test --tests com.example.MyTest.myTestMethod

63. gradle test --exclude-task <task>
Exclude a specific test task.

gradle test --exclude-task integrationTest

64. gradle test --no-rebuild
Run tests without rebuilding.

gradle test --no-rebuild

65. gradle test --info
Show detailed information during testing.

gradle test --info

66. gradle test --debug
Display debug information for tests.

gradle test --debug

67. gradle test --stacktrace
Show stacktrace for test failures.

gradle test --stacktrace

68. gradle test --tests <pattern>
Run tests matching a pattern.

gradle test --tests "com.example.*"

69. gradle test --scan
Create a test scan report.

gradle test --scan

70. gradle test --no-daemon
Run tests without using the Gradle daemon.

gradle test --no-daemon

Custom Tasks

71. gradle tasks --all
List all tasks including those from plugins.

gradle tasks --all

72. gradle <customTaskName>
Run a custom task defined in build.gradle.

gradle myCustomTask

73. gradle <customTaskName> --info
Run a custom task with info logging.

gradle myCustomTask --info

74. gradle <customTaskName> --debug
Run a custom task with debug logging.

gradle myCustomTask --debug

75. gradle <customTaskName> --stacktrace
Run a custom task and show stacktrace for errors.

gradle myCustomTask --stacktrace

76. gradle <customTaskName> --no-daemon
Run a custom task without the Gradle daemon.

gradle myCustomTask --no-daemon

77. gradle <customTaskName> --offline
Run a custom task in offline mode.

gradle myCustomTask --offline

78. gradle <customTaskName> --continue
Run a custom task and continue if some tasks fail.

gradle myCustomTask --continue

79. gradle <customTaskName> --configure-on-demand
Configure a custom task on demand.

gradle myCustomTask --configure-on-demand

80. gradle <customTaskName> --no-rebuild
Run a custom task without rebuilding.

gradle myCustomTask --no-rebuild

81. gradle <customTaskName> --build-cache
Use the build cache for a custom task.

gradle myCustomTask --build-cache

Additional Options

82. gradle --version
Display the Gradle version.

gradle --version

83. gradle --help
Display help information.

gradle --help

84. gradle --no-daemon
Run Gradle without using the daemon.

gradle --no-daemon

85. gradle --offline
Run Gradle in offline mode.

gradle --offline

86. gradle --scan
Create a build scan.

gradle --scan

87. gradle --no-rebuild
Run Gradle without rebuilding.

gradle --no-rebuild

88. gradle --configure-on-demand
Configure Gradle on demand.

gradle --configure-on-demand

89. gradle --build-cache
Use the build cache.

gradle --build-cache

90. gradle --no-configuration-cache
Run Gradle without using configuration cache.

gradle --no-configuration-cache

91. gradle --project-cache
Use the project cache.

gradle --project-cache

92. gradle --continue
Continue building even if some tasks fail.

gradle --continue

Common Issues and Troubleshooting

93. gradle --stop
Stop the Gradle daemon.

gradle --stop

94. gradle --no-daemon --info
Run Gradle without the daemon and with info logging.

gradle --no-daemon --info

95. gradle --no-daemon --debug
Run Gradle without the daemon and with debug logging.

gradle --no-daemon --debug

96. gradle --no-daemon --stacktrace
Run Gradle without the daemon and show stacktrace for errors.

gradle --no-daemon --stacktrace

97. gradle --no-daemon --offline
Run Gradle without the daemon and in offline mode.

gradle --no-daemon --offline

98. gradle --no-daemon --build-cache
Run Gradle without the daemon and use the build cache.

gradle --no-daemon --build-cache

99. gradle --stop --no-daemon
Stop the Gradle daemon and run without it.

gradle --stop --no-daemon

100. gradle --no-daemon --configure-on-demand
Run Gradle without the daemon and configure on demand.

gradle --no-daemon --configure-on-demand

Leave a Reply

Your email address will not be published. Required fields are marked *