Gradle User Guide
Total Page:16
File Type:pdf, Size:1020Kb
Gradle User Guide Version 2.14.1 Copyright © 2007-2015 Hans Dockter, Adam Murdoch Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. Table of Contents I. ABOUT GRADLE 1. Introduction 2. Overview II. WORKING WITH EXISTING BUILDS 3. Installing Gradle 4. Using the Gradle Command-Line 5. The Gradle Wrapper 6. The Gradle Daemon 7. Dependency Management Basics 8. Introduction to multi-project builds 9. Continuous build 10. Using the Gradle Graphical User Interface 11. The Build Environment 12. Troubleshooting 13. Embedding Gradle using the Tooling API III. WRITING GRADLE BUILD SCRIPTS 14. Build Script Basics 15. Build Init Plugin 16. Writing Build Scripts 17. More about Tasks 18. Working With Files 19. Using Ant from Gradle 20. The Build Lifecycle 21. Wrapper Plugin 22. Logging 23. Dependency Management 24. Multi-project Builds 25. Gradle Plugins 26. Standard Gradle plugins 27. The Project Report Plugin 28. The Build Dashboard Plugin 29. Comparing Builds 30. Publishing artifacts 31. The Maven Plugin 32. The Signing Plugin 33. Ivy Publishing (new) 34. Maven Publishing (new) 35. The Distribution Plugin 36. The Announce Plugin 37. The Build Announcements Plugin IV. EXTENDING THE BUILD 38. Writing Custom Task Classes 39. Writing Custom Plugins 40. The Java Gradle Plugin Development Plugin 41. Organizing Build Logic 42. Initialization Scripts 43. The Gradle TestKit V. BUILDING JVM PROJECTS 44. Java Quickstart 45. The Java Plugin 46. Web Application Quickstart 47. The War Plugin 48. The Ear Plugin 49. The Jetty Plugin 50. The Application Plugin 51. The Java Library Distribution Plugin 52. Groovy Quickstart 53. The Groovy Plugin 54. The Scala Plugin 55. The ANTLR Plugin 56. The Checkstyle Plugin 57. The CodeNarc Plugin 58. The FindBugs Plugin 59. The JDepend Plugin 60. The PMD Plugin 61. The JaCoCo Plugin 62. The Sonar Plugin 63. The SonarQube Runner Plugin 64. The OSGi Plugin 65. The Eclipse Plugins 66. The IDEA Plugin VI. THE SOFTWARE MODEL - NEXT GENERATION GRADLE BUILDS 67. Rule based model configuration 68. Software model concepts 69. Implementing model rules in a plugin 70. Building Java Libraries 71. Building Play applications 72. Building native software 73. Extending the software model VII. APPENDIX A. Gradle Samples B. Potential Traps C. The Feature Lifecycle D. Gradle Command Line E. Documentation licenses Glossary List of Examples 4.1. Executing multiple tasks 4.2. Excluding tasks 4.3. Abbreviated task name 4.4. Abbreviated camel case task name 4.5. Selecting the project using a build file 4.6. Selecting the project using project directory 4.7. Forcing tasks to run 4.8. Obtaining information about projects 4.9. Providing a description for a project 4.10. Obtaining information about tasks 4.11. Changing the content of the task report 4.12. Obtaining more information about tasks 4.13. Obtaining detailed help for tasks 4.14. Obtaining information about dependencies 4.15. Filtering dependency report by configuration 4.16. Getting the insight into a particular dependency 4.17. Information about properties 5.1. Running the Wrapper task 5.2. Wrapper task 5.3. Wrapper generated files 5.4. Generating a SHA-256 hash 5.5. Configuring SHA-256 checksum verification 7.1. Declaring dependencies 7.2. Definition of an external dependency 7.3. Shortcut definition of an external dependency 7.4. Usage of Maven central repository 7.5. Usage of JCenter repository 7.6. Usage of a remote Maven repository 7.7. Usage of a remote Ivy directory 7.8. Usage of a local Ivy directory 7.9. Publishing to an Ivy repository 7.10. Publishing to a Maven repository 8.1. Listing the projects in a build 10.1. Launching the GUI 11.1. Setting properties with a gradle.properties file 11.2. Configuring an HTTP proxy 11.3. Configuring an HTTPS proxy 14.1. Your first build script 14.2. Execution of a build script 14.3. A task definition shortcut 14.4. Using Groovy in Gradle's tasks 14.5. Using Groovy in Gradle's tasks 14.6. Declaration of task that depends on other task 14.7. Lazy dependsOn - the other task does not exist (yet) 14.8. Dynamic creation of a task 14.9. Accessing a task via API - adding a dependency 14.10. Accessing a task via API - adding behaviour 14.11. Accessing task as a property of the build script 14.12. Adding extra properties to a task 14.13. Using AntBuilder to execute ant.loadfile target 14.14. Using methods to organize your build logic 14.15. Defining a default task 14.16. Different outcomes of build depending on chosen tasks 16.1. Accessing property of the Project object 16.2. Using local variables 16.3. Using extra properties 16.4. Configuring arbitrary objects 16.5. Configuring arbitrary objects using a script 16.6. Groovy JDK methods 16.7. Property accessors 16.8. Method call without parentheses 16.9. List and map literals 16.10. Closure as method parameter 16.11. Closure delegates 17.1. Defining tasks 17.2. Defining tasks - using strings for task names 17.3. Defining tasks with alternative syntax 17.4. Accessing tasks as properties 17.5. Accessing tasks via tasks collection 17.6. Accessing tasks by path 17.7. Creating a copy task 17.8. Configuring a task - various ways 17.9. Configuring a task - with closure 17.10. Defining a task with closure 17.11. Adding dependency on task from another project 17.12. Adding dependency using task object 17.13. Adding dependency using closure 17.14. Adding a 'must run after' task ordering 17.15. Adding a 'should run after' task ordering 17.16. Task ordering does not imply task execution 17.17. A 'should run after' task ordering is ignored if it introduces an ordering cycle 17.18. Adding a description to a task 17.19. Overwriting a task 17.20. Skipping a task using a predicate 17.21. Skipping tasks with StopExecutionException 17.22. Enabling and disabling tasks 17.23. A generator task 17.24. Declaring the inputs and outputs of a task 17.25. Task rule 17.26. Dependency on rule based tasks 17.27. Adding a task finalizer 17.28. Task finalizer for a failing task 18.1. Locating files 18.2. Creating a file collection 18.3. Using a file collection 18.4. Implementing a file collection 18.5. Creating a file tree 18.6. Using a file tree 18.7. Using an archive as a file tree 18.8. Specifying a set of files 18.9. Copying files using the copy task 18.10. Specifying copy task source files and destination directory 18.11. Selecting the files to copy 18.12. Copying files using the copy() method without up-to-date check 18.13. Copying files using the copy() method with up-to-date check 18.14. Renaming files as they are copied 18.15. Filtering files as they are copied 18.16. Nested copy specs 18.17. Using the Sync task to copy dependencies 18.18. Creating a ZIP archive 18.19. Creation of ZIP archive 18.20. Configuration of archive task - custom archive name 18.21. Configuration of archive task - appendix & classifier 19.1. Using an Ant task 19.2. Passing nested text to an Ant task 19.3. Passing nested elements to an Ant task 19.4. Using an Ant type 19.5. Using a custom Ant task 19.6. Declaring the classpath for a custom Ant task 19.7. Using a custom Ant task and dependency management together 19.8. Importing an Ant build 19.9. Task that depends on Ant target 19.10. Adding behaviour to an Ant target 19.11. Ant target that depends on Gradle task 19.12. Renaming imported Ant targets 19.13. Setting an Ant property 19.14. Getting an Ant property 19.15. Setting an Ant reference 19.16. Getting an Ant reference 19.17. Fine tuning Ant logging 20.1. Single project build 20.2. Hierarchical layout 20.3. Flat layout 20.4. Modification of elements of the project tree 20.5. Adding of test task to each project which has certain property set 20.6. Notifications 20.7. Setting of certain property to all tasks 20.8. Logging of start and end of each task execution 22.1. Using stdout to write log messages 22.2. Writing your own log messages 22.3. Using SLF4J to write log messages 22.4. Configuring standard output capture 22.5. Configuring standard output capture for a task 22.6. Customizing what Gradle logs 23.1. Definition of a configuration 23.2. Accessing a configuration 23.3. Configuration of a configuration 23.4. Module dependencies 23.5. Artifact only notation 23.6. Dependency with classifier 23.7. Iterating over a configuration 23.8. Client module dependencies - transitive dependencies 23.9. Project dependencies 23.10. File dependencies 23.11. Generated file dependencies 23.12. Gradle API dependencies 23.13. Gradle's Groovy dependencies 23.14. Excluding transitive dependencies 23.15. Optional attributes of dependencies 23.16. Collections and arrays of dependencies 23.17. Dependency configurations 23.18. Dependency configurations for project 23.19. Configuration.copy 23.20. Accessing declared dependencies 23.21. Configuration.files 23.22. Configuration.files with spec 23.23. Configuration.copy 23.24. Configuration.copy vs. Configuration.files 23.25. Adding central Maven repository 23.26. Adding Bintray's JCenter Maven repository 23.27. Using Bintrays's JCenter with HTTP 23.28. Adding the local Maven cache as a repository 23.29.