Skip to content

Commit e686a3c

Browse files
toabctlclaude
andcommitted
feat(maven): enable caching for Maven dependencies
Configure Maven local repository to use /var/cache/melange/m2repository, which is persisted when a cache-dir is provided. This allows Maven builds to reuse downloaded dependencies across builds which is very useful because some java projects have a lot of deps to download (eg. apicurio-registry needs more than 1 GB deps). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent df9cc47 commit e686a3c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/build/pipelines/maven/configure-mirror.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ needs:
44
- busybox
55
pipeline:
66
- runs: |
7+
# Use melange's build cache for downloaded dependencies if mounted from host
8+
MAVEN_LOCAL_REPO="/var/cache/melange/m2repository"
9+
LOCAL_REPO_CONFIG=""
10+
if [ -d "/var/cache/melange" ]; then
11+
mkdir -p "$MAVEN_LOCAL_REPO"
12+
LOCAL_REPO_CONFIG="<localRepository>${MAVEN_LOCAL_REPO}</localRepository>"
13+
fi
14+
715
# Maven checks $USER/.m2, we set $HOME to /home/build but it hardcodes $USER somehow
816
mkdir -p /root/.m2
917
cat > /root/.m2/settings.xml <<EOF
1018
<settings>
19+
${LOCAL_REPO_CONFIG}
1120
<mirrors>
1221
<mirror>
1322
<id>google-maven-central</id>

pkg/build/pipelines/maven/pombump.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ inputs:
3333

3434
pipeline:
3535
- runs: |
36+
# Use melange's build cache for downloaded dependencies if mounted from host
37+
MAVEN_LOCAL_REPO="/var/cache/melange/m2repository"
38+
if [ -d "/var/cache/melange" ]; then
39+
mkdir -p "$MAVEN_LOCAL_REPO"
40+
mkdir -p /root/.m2
41+
cat > /root/.m2/settings.xml <<EOF
42+
<settings>
43+
<localRepository>${MAVEN_LOCAL_REPO}</localRepository>
44+
</settings>
45+
EOF
46+
fi
47+
3648
PATCH_FILE_FLAG=""
3749
PROPERTIES_FILE_FLAG=""
3850
DEPENDENCIES_FLAG=""

0 commit comments

Comments
 (0)