镜像版本:maven:3.8.7-eclipse-temurin-11
一、配置 用户级 settings.xml
- mvn 手动指定配置文件
COPY pom.xml /tmp/pom.xml
RUN mvn -B -f /tmp/pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve
or
- mvn 自动检索、加载配置文件
COPY settings.xml /usr/share/maven/ref/
MAVEN 镜像 读取配置文件如下
[DEBUG] Reading global settings from/usr/share/maven/conf/settings.xml
[DEBUG] Reading user settings from/root/.m2/settings.xml
----- 只读取 settings.xml ,不读取 settings-docker.xml ,须特别留意。-----
二、dockerfile
FROM maven:3.8.7-eclipse-temurin-11
# COPY settings-docker.xml /usr/share/maven/ref/settings.xml
RUN curl -SL http://ip/hfs/install/maven/settings-robintest.xml -o /usr/share/maven/ref/settings.xml
三、执行入口文件 /usr/local/bin/mvn-entrypoint.sh
解析
#! /bin/sh -eu
# Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG}
# So the initial ~/.m2 is set with expected content.
# Don't override, as this is just a reference setup
copy_reference_files() {
local log="$MAVEN_CONFIG/copy_reference_file.log"
local ref="/usr/share/maven/ref"
if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then
cd "${ref}"
local reflink=""
if cp --help 2>&1 | grep -q reflink ; then
reflink="--reflink=auto"
fi
if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then
# destination is empty...
echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}"
cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}"
else
# destination is non-empty, copy file-by-file
echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}"
find . -type f -exec sh -eu -c '
log="${1}"
shift
reflink="${1}"
shift
for f in "$@" ; do
if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then
mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")"
cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}"
fi
done
' _ "${log}" "${reflink}" {} +
fi
echo >> "${log}"
else
echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..."
fi
}
owd="$(pwd)"
copy_reference_files
unset MAVEN_CONFIG
cd "${owd}"
unset owd
exec "$@"
网友评论