Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building with Gradle

Introduction to Gradle

  • Login to see the comments

  • Be the first to like this

Building with Gradle

  1. 1. Building with Laurynas Tretjakovas 1Kaunas Java User Group, 2014
  2. 2. Why Gradle? • Ant makes you reinvent the wheel every time; • Ant build scripts can get hard to maintain very quickly; • Maven does not care about your project, you must make sure that your project works well with Maven – it enforces convention; • You must do everything “The Maven Way” or implement custom plugins; • Gradle combines the power and flexibility of Ant with dependency management of Ivy and conventions of Maven; • Gradle is a programming build tool with DSL based on Groovy. 2Kaunas Java User Group, 2014
  3. 3. Features • Build Java, Android, Scala, Groovy, c++ and others; • Dependency management; • Incremental builds; • Task exclusion; • Supports plugins; • Multi-project builds; • Hook into any build step; • Camel case invocation – helloWorld task can be called by doing gradle hW; • Gradle wrapper; • HTML test reporting; • Ant integration. 3Kaunas Java User Group, 2014
  4. 4. Hello World • Gradle has two phases – configuration and execution; • Run each task and see what gets printed out • How would you do that with Maven? 4Kaunas Java User Group, 2014
  5. 5. Tasks • Gradle has task types for most common operations; • You can specify inputs and outputs for a task. If those haven‘t changed since last execution, it won‘t be executed again; • You can create your own task types by extending DefaultTask. 5Kaunas Java User Group, 2014
  6. 6. Task Dependencies • shouldRunAfter is used for task ordering, not for dependencies. For example, it can be used for running unit tests before integration tests. This may be ignored during parallel task execution; • mustRunAfter will never be ignored, use this for strong ordering; 6Kaunas Java User Group, 2014
  7. 7. Building Java Projects • Simply include the plugin 7Kaunas Java User Group, 2014
  8. 8. Java Plugin Tasks • compileJava - compiles production Java source files using javac; • processResources - copies production resources into the production classes directory; • classes - assembles the production classes directory; • compileTestJava - compiles test Java source files using javac; • processTestResources - Copies test resources into the test classes directory; • testClasses - Assembles the test classes directory; • jar - Assembles the jar file; • javadoc - Generates API documentation for the production Java source, using Javadoc; • test - Runs the unit tests using JUnit or TestNG. 8Kaunas Java User Group, 2014
  9. 9. Lifecycle Tasks • assemble - Assembles all the archives in the project; • check - Performs all verification tasks in the project; • build - Performs a full build of the project (check and assemble); • buildNeeded - Performs a full build of the project and all projects it depends on; • buildDependents - Performs a full build of the project and all projects which depend on it. 9Kaunas Java User Group, 2014
  10. 10. Dependency Management 10Kaunas Java User Group, 2014
  11. 11. Source Sets 11Kaunas Java User Group, 2014
  12. 12. Test Reporting • Tests have XML and HTML reporting by default; • If you have multiple test tasks, you will need a separate reporting task; • HTML reporting includes execution time, stdout and stderr outputs. 12Kaunas Java User Group, 2014
  13. 13. The Gradle Wrapper • Gradle wrapper allows developers to use gradle, without even downloading it manually; • Every developer will be using the same version for building and CI server won‘t need additional configuration; • Run wrapper task once, it will create gradle executables which you will commit into source control; • You can specify the version or full url. 13Kaunas Java User Group, 2014
  14. 14. Init Scripts • Init scripts can be run each time before task execution; • You can pass init scripts with -I flag or include .gradle files in GRADLE_HOME/init.d/ directory; • This can be useful for enterprise policies and repositories. 14Kaunas Java User Group, 2014
  15. 15. Roadmap • Incremental Java compilation; • Persistable and much faster configuration; • Improved parallel execution; • Global cache; • Dependency variants; • Watcher mode; 15Kaunas Java User Group, 2014
  16. 16. Demo • Sources - 16Kaunas Java User Group, 2014
  17. 17. Thank You! Laurynas Tretjakovas 17Kaunas Java User Group, 2014