Skip to content

Commit ffebb7e

Browse files
committed
Add example project
1 parent 2ddaaf9 commit ffebb7e

File tree

11 files changed

+658
-1
lines changed

11 files changed

+658
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
target/
22
.idea/
3-
.mvn/.gradle-enterprise/
3+
.mvn/.develocity/
44
data/timing.txt

.mvn/develocity.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<develocity xmlns="https://www.gradle.com/develocity-maven"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="https://www.gradle.com/develocity-maven https://www.gradle.com/schema/develocity-maven.xsd">
4+
<server>
5+
<url>https://dpeuniversity-develocity.gradle.com</url>
6+
</server>
7+
<buildScan>
8+
<!-- Optional, Add tags and values that make it easier to find the Build Scan related to this lab. -->
9+
<!-- See https://docs.gradle.com/develocity/maven-extension/current/#extending_build_scans -->
10+
<!-- for more information about adding custom information to a Build Scan -->
11+
<tags>
12+
<tag>dpeuni-maven-build-cache-deep-dive-outputs-overwrite-inputs</tag>
13+
</tags>
14+
<values>
15+
<value>
16+
<name>Course</name>
17+
<value>Maven Build Cache Deep Dive</value>
18+
</value>
19+
</values>
20+
</buildScan>
21+
<buildCache>
22+
<remote>
23+
<enabled>false</enabled>
24+
</remote>
25+
</buildCache>
26+
</develocity>

.mvn/extensions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<extensions>
2+
<extension>
3+
<groupId>com.gradle</groupId>
4+
<artifactId>develocity-maven-extension</artifactId>
5+
<version>1.21.4</version>
6+
</extension>
7+
</extensions>

.mvn/wrapper/maven-wrapper.properties

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# DPE University Training
2+
3+
[<img width="10%" height="10%" src="https://user-images.githubusercontent.com/120980/174325546-8558160b-7f16-42cb-af0f-511849f22ebc.png">](https://dpeuniversity.gradle.com/)
4+
Checkout all the **free** Maven, Gradle, and DPE courses at the [DPE University][dpe-university]!
5+
6+
## Maven Build Cache Deep Dive - Lab 05: Outputs Overwrite Inputs
7+
8+
This is a hands-on exercise to go along with the [Maven Build Cache Deep Dive][course-url] training module. In this exercise you will go over the following:
9+
10+
- How to deal with cache misses caused by outputs that overwrite inputs of a previously run goal.
11+
12+
## Prerequisites
13+
14+
- Finished going through the _Troubleshooting Build Cache Misses_ section in Maven Build Cache Deep Dive.
15+
- Java 11+
16+
17+
Steps
18+
-----
19+
20+
1. If you have not completed the previous labs, authenticate Maven with the Develocity server.
21+
22+
> [!NOTE]
23+
> As part of taking this **free** course, you have access to a training instance of Develocity located at:
24+
> ```
25+
> https://dpeuniversity-develocity.gradle.com/
26+
> ```
27+
> [Sign in][develocity-url] to this Develocity server using the same account you use for the DPE University.
28+
>
29+
> This server is configured so users can only access the Build Scan® and Build Cache entries they publish.
30+
31+
Run the following command and follow the instructions in your terminal:
32+
33+
```shell
34+
./mvnw com.gradle:develocity-maven-extension:provision-access-key
35+
```
36+
> [!NOTE]
37+
> For more ways to authenticate, see the [authentication guide](https://docs.gradle.com/enterprise/maven-extension/#authenticating_with_gradle_enterprise) to see how to provide credentials.
38+
39+
2. In this example the `data` directory represents content used by the build that _may_ be in another repository, a external application, or other resources needed by the build.
40+
41+
This directory has already been added as an input, see the `pom.xml`.
42+
43+
3. Run the build **multiple times**:
44+
45+
```shell
46+
./mvnw clean install
47+
```
48+
49+
4. Notice how the test goal was not cached (the tests run on every build). Open the Build Scan to see more details.
50+
51+
Open `HelloWorldTest.java` and look at the `writeToResourcesDir` test method, this test writes to a directory that is used as an input. This changed input will cause a cache miss on the next build.
52+
53+
5. Fix the test.
54+
55+
While it is possible to configure Develocity to [ignore a whole file](https://docs.gradle.com/enterprise/maven-extension/#ignoring_arbitrary_files), when possible it's best to fix the cause of the problem. In this case, update the test to write to a different location (a temp directory or the `target/` dir).
56+
57+
```diff
58+
- // resolve a file in the data dir (data/timing.txt)
59+
- Path timingFile = Paths.get("data/timing.txt");
60+
+ // resolve a file relative to the `target` directory
61+
+ Path timingFile = Paths.get("./target/test-output/timing.txt");
62+
+ Files.createDirectories(timingFile.getParent());
63+
```
64+
6. Run the build **multiple times**:
65+
66+
```shell
67+
./mvnw clean install
68+
```
69+
70+
After the first run the test goal will have a cache hit!
71+
72+
## Solution Reference
73+
74+
To see the solution to the lab, check out the [`solution`](https://github.com/gradle/outputs-overwrite-inputs-maven-build-cache-lab/commit/solution) branch of this project.
75+
76+
## More Free Labs & Courses
77+
78+
Be sure to check out our other **free** [courses][dpe-university] and [labs](https://github.com/gradle?q=dpe-university)!
79+
80+
**Related courses:**
81+
- [Maven - Build Cache Deep Dive][course-url]
82+
- [Maven - Maintaining an Optimized Build Cache](https://dpeuniversity.gradle.com/c/42cf9d626302011526c4a0536b26af929b5bef58)
83+
- [Develocity - How to Use Build Scans](https://dpeuniversity.gradle.com/c/0b0b3e4a8d21709ff39074e9962eee6ca4276dc1)
84+
85+
**Related labs:**
86+
- [Lab 01 - Using the local build cache](https://github.com/gradle/getting-started-maven-build-cache-lab)
87+
- [Lab 02 - Missing Inputs With Build Caching](https://github.com/gradle/missing-inputs-maven-build-cache-lab)
88+
- [Lab 03 - Add Build Cache Support to any Maven Plugin](https://github.com/gradle/caching-any-plugin-maven-build-cache-lab)
89+
- [Lab 04 - Handling Cache Misses with Normalization](https://github.com/gradle/cache-misses-maven-build-cache-lab)
90+
- [Lab 05 - Outputs Overwrite Inputs](https://github.com/gradle/outputs-overwrite-inputs-maven-build-cache-lab)
91+
- [Lab 06 - Maintaining an Optimized Build Cache](https://github.com/gradle/maintaining-optimized-cache-maven-build-cache-lab)
92+
93+
[course-url]: https://dpeuniversity.gradle.com/c/47262fea1e74b719afb590d8cb3f8280bf2af732
94+
[dpe-university]: https://dpeuniversity.gradle.com/
95+
[develocity-url]: https://dpeuniversity-develocity.gradle.com/

data/hello.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello Brent Spiner!

0 commit comments

Comments
 (0)