-
Notifications
You must be signed in to change notification settings - Fork 15
/
clean_repository.sh
57 lines (48 loc) · 1.44 KB
/
clean_repository.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
BASE_M2=~/.m2/repository
SAVED_M2=$(mktemp -d /tmp/m2.repository.XXXXXX)
SETTINGS=$(mktemp /tmp/m2.settings.xml.XXXXXX)
# Download all dependencies to local m2 repository
mvn -Dmaven.repo.local=$BASE_M2 dependency:resolve
# backup repository settings and move m2 repository to tmp directory
mv $BASE_M2/* $SAVED_M2
# remove "central" indication
find $SAVED_M2 -type f -name "maven-metadata-central.xml*" | sed "p;s/-central//" | xargs -n2 mv
# custom settings
cat << END_TOKEN > ${SETTINGS}
<settings>
<mirrors>
<mirror>
<id>mycentral</id>
<name>My Central</name>
<url>file:${SAVED_M2}</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>mycentral</id>
<name>mycentra</name>
<url>file:${SAVED_M2}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
END_TOKEN
# fetch deps again
mvn -s ${SETTINGS} -Dmaven.repo.local=$BASE_M2 dependency:resolve
rm -R $SAVED_M2
rm $SETTINGS