|
1 | | -# Build phases |
| 1 | +# Gradle Kata: Build phases |
2 | 2 |
|
3 | | -## Configuration vs execution time |
| 3 | +This kata explores the three stages of a gradle build: |
| 4 | +- Initialization |
| 5 | +- Configuration |
| 6 | +- Execution |
4 | 7 |
|
5 | | -The `build.gradle` script in this exercise contains a property and two tasks: |
| 8 | +## Setup |
6 | 9 |
|
7 | | -- `setTheValue` changes the value of `theValue` |
8 | | -- `printTheValue` prints the value of `theValue` |
| 10 | +Run `source setup.sh` |
9 | 11 |
|
10 | | -Predict the outcome of the following commands: |
| 12 | +This will create a new gradle project in the `exercise` directory and add several tasks to `build.gradle` |
11 | 13 |
|
12 | | -- `./gradlew printTheValue` |
13 | | -- `./gradlew setTheValue printTheValue` |
| 14 | +## The task |
14 | 15 |
|
15 | | -Run the commands and note the printed values. |
| 16 | +- Examine the `build.gradle` script. It contains a property and two tasks: |
16 | 17 |
|
17 | | -- Q: Did the output match your expectations? If not, what tripped you up? |
| 18 | + - `setTheValue` changes the value of `theValue` |
| 19 | + - `printTheValue` prints the value of `theValue` |
| 20 | + |
| 21 | +- Predict the outcome of the following commands: |
| 22 | + |
| 23 | + - `./gradlew printTheValue` |
| 24 | + - `./gradlew setTheValue printTheValue` |
18 | 25 |
|
19 | | -Make a small change to the `build.gradle` such that: |
| 26 | +- Run the commands and note the printed values. |
| 27 | + |
| 28 | +- Q: Did the output match your expectations? If not, what tripped you up? |
20 | 29 |
|
21 | | -- the `printTheValue`-task ends up printing `The value currently is: 200`, |
22 | | -- when run after the `printTheValue` task and |
23 | | -- while still using the `theValue` variable |
| 30 | +- Change `printTheValue` so that the `message` is defined inside the doLast block |
| 31 | + ``` |
| 32 | + task 'printTheValue' { |
| 33 | + group 'Value' |
| 34 | + description 'Prints the value' |
| 35 | +
|
| 36 | + doLast { |
| 37 | + def message = "The value currently is: ${theValue}" |
| 38 | + println message |
| 39 | + } |
| 40 | + } |
| 41 | + ``` |
| 42 | +
|
| 43 | +- Run `./gradlew setTheValue printTheValue` again |
| 44 | +- Why is the increased `theValue` printed this time, when it wasn't before? |
0 commit comments