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. 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. 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. 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. 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
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. 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
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. 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. 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. Roadmap
• Incremental Java compilation;
• Persistable and much faster configuration;
• Improved parallel execution;
• Global cache;
• Dependency variants;
• Watcher mode;
15Kaunas Java User Group, 2014