[SDFAB-872] Allow to use local maven cache via env variable

If USE_LOCAL_SNAPSHOT_ARTIFACTS=true while we are building from source code, it will use the 
snapshot artifacts in local maven cache rather than fetching from remote repositories. It is not 
effective when we are not building from source code.

Change-Id: I10cbaac0601eff40b1a7cb7c45c532bb17914c0d
diff --git a/mvn_settings.sh b/mvn_settings.sh
index b2e72e0..846d827 100755
--- a/mvn_settings.sh
+++ b/mvn_settings.sh
@@ -52,6 +52,7 @@
           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
   <!--PROXY-->
   <!--EXTRA-->
+  <!--MIRRORS-->
 </settings>
 EOF
 
@@ -82,6 +83,22 @@
   rm mvn_settings.proxy.xml
 fi
 
+if [ "$USE_LOCAL_SNAPSHOT_ARTIFACTS" == "true" ]; then
+  # When using local SNAPSHOT artifacts, we need to prevent maven to fetch from the Sonatype repository.
+  # However, we need to point to a valid maven repository otherwise maven fails. For this reason we
+  # mirror snapshots to maven central (that won't contain any SNAPSHOT artifacts).
+  echo "    <mirrors>
+      <mirror>
+        <id>central_snapshots</id>
+        <name>central_snapshots</name>
+        <url>https://repo.maven.apache.org/maven2</url>
+        <mirrorOf>snapshots</mirrorOf>
+      </mirror>
+    </mirrors>" >> mvn_settings.mirror.xml
+  sed -i '' -e '/<!--MIRRORS-->/r mvn_settings.mirror.xml' mvn_settings.xml
+  rm mvn_settings.mirror.xml
+fi
+
 if [ -f mvn_settings.extra.xml ] ; then
   sed -i 's/<!--EXTRA-->/r mvn_settings.extra.xml' mvn_settings.xml
 fi