Gradle Fundamentals
Ant
XML build Script:
- hard to read
- difficult to maintain
Maven
- many conventions
- highly extendable
- hard to read
- could be difficult to maintain
Gradle Build
- Gradle has build file
- Typically build.gradle
- This contains tasks (task based)
- plugins
- dependencies
- mostly tasks
ex:
Introduction to the Gradle Wrapper
e.g.
Now can run gradlew build
- download the gradle
- then build
Writing Simple Tasks
Task:
- code that grade executes
- has a lifecycle
- has properties
- has ‘actions’ (code to be execute)
- has dependencies
E.g. (in groovy)
- project is the top level object
Running a Task
— gradle Task4
e.g.
Build Phases
- initialisation phases: used to configure multi projects builds
- Configuration Phase: executes code in the task that’s not the action e.g. .. description “some thing”…
- Excution Phase: doLast, doFirst
Task Dependencies
e.g.
Setting properties on Tasks
e.g.
Task Dependencies
- understand how tasks can be linked
Using mustRunAfter and shouldRunAfter
- mustRunAfter
- if two tasks execute on must run after the other
- shouldRUnAfter
- if two tasks execute one should run after the other
- this ignores circular dependencies
- finalised by (incubating in 2.6)
- inverted dependency
Introduction to Typed Tasks
- suppose we want something more complex
- can be reuse the task code
- e.g. copying files
- Open file/ read file/ write file
- e.g. Zipping files
- would like this to be reused
Using the Copy task
copying some images:
e.g.
integral to Java Plugin
Defines:
- a source set
- task to compile the test
- task to run the test
Source Set
- Looks for unit tests in src/test/java
- Outputs to build/classes/test
- Reports to build/reports/test
Filtering
- Can filter to only run a subset of tests
- Single test
- All tests from a package
- Wildcard is supported e.g.
Other Testing
- Integration tests for example
- add the cradle-testsets-plugin
- add a testSet
- set other configurations parameters
- set output reports directory
buildscript:
- add dependencies for build script not for tasks
allprojects:
- apply all the content to all the projects when built
Wrapper
- provides a specific version of Gradle to the project
- get consistent builds
- gradlew.bat on Windows
- cradle shell script on *unix
- Standard task
- always available
e.g.
Running the Wrapper
- run the specific gradle
- if not installed will download and install specific gradle