Gradle User Guide
Total Page:16
File Type:pdf, Size:1020Kb
Gradle User Guide Version 2.2.1 Copyright © 2007-2012 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 1. Introduction 1.1. About this user guide 2. Overview 2.1. Features 2.2. Why Groovy? 3. Tutorials 3.1. Getting Started 4. Installing Gradle 4.1. Prerequisites 4.2. Download 4.3. Unpacking 4.4. Environment variables 4.5. Running and testing your installation 4.6. JVM options 5. Troubleshooting 5.1. Working through problems 5.2. Getting help 6. Build Script Basics 6.1. Projects and tasks 6.2. Hello world 6.3. A shortcut task definition 6.4. Build scripts are code 6.5. Task dependencies 6.6. Dynamic tasks 6.7. Manipulating existing tasks 6.8. Shortcut notations 6.9. Extra task properties 6.10. Using Ant Tasks 6.11. Using methods 6.12. Default tasks 6.13. Configure by DAG 6.14. Where to next? 7. Java Quickstart 7.1. The Java plugin 7.2. A basic Java project 7.3. Multi-project Java build 7.4. Where to next? 8. Dependency Management Basics 8.1. What is dependency management? 8.2. Declaring your dependencies 8.3. Dependency configurations 8.4. External dependencies 8.5. Repositories 8.6. Publishing artifacts 8.7. Where to next? 9. Groovy Quickstart 9.1. A basic Groovy project 9.2. Summary 10. Web Application Quickstart 10.1. Building a WAR file 10.2. Running your web application 10.3. Summary 11. Using the Gradle Command-Line 11.1. Executing multiple tasks 11.2. Excluding tasks 11.3. Continuing the build when a failure occurs 11.4. Task name abbreviation 11.5. Selecting which build to execute 11.6. Obtaining information about your build 11.7. Dry Run 11.8. Summary 12. Using the Gradle Graphical User Interface 12.1. Task Tree 12.2. Favorites 12.3. Command Line 12.4. Setup 13. Writing Build Scripts 13.1. The Gradle build language 13.2. The Project API 13.3. The Script API 13.4. Declaring variables 13.5. Some Groovy basics 14. Tutorial - 'This and That' 14.1. Directory creation 14.2. Gradle properties and system properties 14.3. Configuring the project using an external build script 14.4. Configuring arbitrary objects 14.5. Configuring arbitrary objects using an external script 14.6. Caching 15. More about Tasks 15.1. Defining tasks 15.2. Locating tasks 15.3. Configuring tasks 15.4. Adding dependencies to a task 15.5. Ordering tasks 15.6. Adding a description to a task 15.7. Replacing tasks 15.8. Skipping tasks 15.9. Skipping tasks that are up-to-date 15.10. Task rules 15.11. Finalizer tasks 15.12. Summary 16. Working With Files 16.1. Locating files 16.2. File collections 16.3. File trees 16.4. Using the contents of an archive as a file tree 16.5. Specifying a set of input files 16.6. Copying files 16.7. Using the Sync task 16.8. Creating archives 17. Using Ant from Gradle 17.1. Using Ant tasks and types in your build 17.2. Importing an Ant build 17.3. Ant properties and references 17.4. API 18. Logging 18.1. Choosing a log level 18.2. Writing your own log messages 18.3. Logging from external tools and libraries 18.4. Changing what Gradle logs 19. The Gradle Daemon 19.1. Enter the daemon 19.2. Reusing and expiration of daemons 19.3. Usage and troubleshooting 19.4. Configuring the daemon 20. The Build Environment 20.1. Configuring the build environment via gradle.properties 20.2. Accessing the web via a proxy 21. Gradle Plugins 21.1. Types of plugins 21.2. Applying plugins 21.3. Applying plugins with the plugins DSL 21.4. Finding community plugins 21.5. What plugins do 21.6. Conventions 21.7. More on plugins 22. Standard Gradle plugins 22.1. Language plugins 22.2. Incubating language plugins 22.3. Integration plugins 22.4. Incubating integration plugins 22.5. Software development plugins 22.6. Incubating software development plugins 22.7. Base plugins 22.8. Third party plugins 23. The Java Plugin 23.1. Usage 23.2. Source sets 23.3. Tasks 23.4. Project layout 23.5. Dependency management 23.6. Convention properties 23.7. Working with source sets 23.8. Javadoc 23.9. Clean 23.10. Resources 23.11. CompileJava 23.12. Incremental Java compilation 23.13. Test 23.14. Jar 23.15. Uploading 24. The Groovy Plugin 24.1. Usage 24.2. Tasks 24.3. Project layout 24.4. Dependency management 24.5. Automatic configuration of groovyClasspath 24.6. Convention properties 24.7. Source set properties 24.8. GroovyCompile 25. The Scala Plugin 25.1. Usage 25.2. Tasks 25.3. Project layout 25.4. Dependency management 25.5. Automatic configuration of scalaClasspath 25.6. Convention properties 25.7. Source set properties 25.8. Fast Scala Compiler 25.9. Compiling in external process 25.10. Incremental compilation 25.11. Eclipse Integration 25.12. IntelliJ IDEA Integration 26. The War Plugin 26.1. Usage 26.2. Tasks 26.3. Project layout 26.4. Dependency management 26.5. Convention properties 26.6. War 26.7. Customizing 27. The Ear Plugin 27.1. Usage 27.2. Tasks 27.3. Project layout 27.4. Dependency management 27.5. Convention properties 27.6. Ear 27.7. Customizing 27.8. Using custom descriptor file 28. The Jetty Plugin 28.1. Usage 28.2. Tasks 28.3. Project layout 28.4. Dependency management 28.5. Convention properties 29. The Checkstyle Plugin 29.1. Usage 29.2. Tasks 29.3. Project layout 29.4. Dependency management 29.5. Configuration 30. The CodeNarc Plugin 30.1. Usage 30.2. Tasks 30.3. Project layout 30.4. Dependency management 30.5. Configuration 31. The FindBugs Plugin 31.1. Usage 31.2. Tasks 31.3. Dependency management 31.4. Configuration 32. The JDepend Plugin 32.1. Usage 32.2. Tasks 32.3. Dependency management 32.4. Configuration 33. The PMD Plugin 33.1. Usage 33.2. Tasks 33.3. Dependency management 33.4. Configuration 34. The JaCoCo Plugin 34.1. Getting Started 34.2. Configuring the JaCoCo Plugin 34.3. JaCoCo Report configuration 34.4. JaCoCo specific task configuration 34.5. Tasks 34.6. Dependency management 35. The Sonar Plugin 35.1. Usage 35.2. Analyzing Multi-Project Builds 35.3. Analyzing Custom Source Sets 35.4. Analyzing languages other than Java 35.5. Setting Custom Sonar Properties 35.6. Configuring Sonar Settings from the Command Line 35.7. Tasks 36. The Sonar Runner Plugin 36.1. Sonar Runner version and compatibility 36.2. Getting started 36.3. Configuring the Sonar Runner 36.4. Specifying the Sonar Runner version 36.5. Analyzing Multi-Project Builds 36.6. Analyzing Custom Source Sets 36.7. Analyzing languages other than Java 36.8. More on configuring Sonar properties 36.9. Setting Sonar Properties from the Command Line 36.10. Controlling the Sonar Runner process 36.11. Tasks 37. The OSGi Plugin 37.1. Usage 37.2. Implicitly applied plugins 37.3. Tasks 37.4. Dependency management 37.5. Convention object 37.6. 38. The Eclipse Plugin 38.1. Usage 38.2. Tasks 38.3. Configuration 38.4. Customizing the generated files 39. The IDEA Plugin 39.1. Usage 39.2. Tasks 39.3. Configuration 39.4. Customizing the generated files 39.5. Further things to consider 40. The ANTLR Plugin 40.1. Usage 40.2. Tasks 40.3. Project layout 40.4. Dependency management 40.5. Convention properties 40.6. Source set properties 41. The Project Report Plugin 41.1. Usage 41.2. Tasks 41.3. Project layout 41.4. Dependency management 41.5. Convention properties 42. The Announce Plugin 42.1. Usage 42.2. Configuration 43. The Build Announcements Plugin 43.1. Usage 44. The Distribution Plugin 44.1. Usage 44.2. Tasks 44.3. Distribution contents 45. The Application Plugin 45.1. Usage 45.2. Tasks 45.3. Convention properties 45.4. Including other resources in the distribution 46. The Java Library Distribution Plugin 46.1. Usage 46.2. Tasks 46.3. Including other resources in the distribution 47. Build Init Plugin 47.1. Tasks 47.2. What to set up 47.3. Build init types 48. Wrapper Plugin 48.1. Usage 48.2. Tasks 49. The Build Dashboard Plugin 49.1. Usage 49.2. Tasks 49.3. Project layout 49.4. Dependency management 49.5. Configuration 50. The Java Gradle Plugin Development Plugin 50.1. Usage 51. Dependency Management 51.1. Introduction 51.2. Dependency Management Best Practices 51.3. Dependency configurations 51.4. How to declare your dependencies 51.5. Working with dependencies 51.6. Repositories 51.7. How dependency resolution works 51.8. Fine-tuning the dependency resolution process 51.9. The dependency cache 51.10. Strategies for transitive dependency management 52. Publishing artifacts 52.1. Introduction 52.2. Artifacts and configurations 52.3. Declaring artifacts 52.4. Publishing artifacts 52.5. More about project libraries 53. The Maven Plugin 53.1. Usage 53.2. Tasks 53.3. Dependency management 53.4. Convention properties 53.5. Convention methods 53.6. Interacting with Maven repositories 54. The Signing Plugin 54.1. Usage 54.2. Signatory credentials 54.3. Specifying what to sign 54.4. Publishing the signatures 54.5. Signing POM files 55. Building native binaries 55.1. Supported languages 55.2.