2 回答

TA貢獻1921條經驗 獲得超9個贊
由于您可以檢測到pom.xml
兩次提交之間的更改列表:
git diff --name-status <commit1> <commit2>
(另見“ Git pull 后的細節變化”)
,您可以制作一個腳本,該腳本將為每個模塊執行一個mvn clean install
.

TA貢獻1865條經驗 獲得超7個贊
我已經完成了一個可以滿足我要求的腳本。
該項目是一個 POM 項目,其中包含包含應用程序主要項目的子 POM 項目。我通過讓當前工作分支調用來實現了預期的結果git diff --name-status HEAD@{1} <current_branch>。
這得到了項目中已更改文件的列表,然后我將其拆分為一個數組。不幸的是,我無法讓拆分正常工作,因此數組被組織為更改類型,后跟文件路徑。
然后我檢查了字符串大小,跳過了單個字符串。下一步是將字符串拆分為一個數組,由 . 分隔/。如果根路徑檢查它是否存在于數組中,如果不存在則添加。
最后,遍歷根路徑數組并執行 maven 調用。
################################################################################
#
# License:.....GNU General Public License v3.0
# Author:......CodeMonkey
# Date:........14 November 2018
# Title:.......GitMavenCleanInstall.sh
# Description: This script is designed to cd to a set Maven POM Project,
# perform a git remote update and pull, and clean install the changed
# files projects.
# Notice:......The project structure this script was originally set to target
# is structured as a Maven POM Project that contains several sub-POM Projects.
# The sub-POM Projects contain Maven Java Application projects. The targets
# should be easy to change, and allow for others to target other structures.
#
################################################################################
#
# Change History: N/A
#
################################################################################
#!/bin/bash
#Function to check if array has element
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
#Navigate to the POM Project
cd PATH/TO/POM/PROJECT
#Remote update
git remote update -p
#Pull
git pull
#Get the current working branch
CURRENT_BRANCH="$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')"
#Get the output of the command git diff
GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"
#Split the diff output into an array
read =a GIT_DIFF_OUTPUT_ARY <<< $GIT_DIF_OUTPUT
#Declare empty array for root path
declare -a GIT_DIFF_OUTPUT_ARY_ROOT_PATH=()
FORWARD='/'
#Loop diff output array
for i in "$GIT_DIFF_OUTPUT_ARY[@]}"
do
#Check that the string is not 1 Character
if [[ "$(echo -n $1 | wc -m)" != 1 ]]
then
#Split the file path by /
IFS='/' read -ra SPLIT <<< $i
#Concatenate first path + / + second path
path=${SPLIT[0]}$FORWARD${SPLIT[1]}
#Call function to see if it already exists in the root path array
containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
if [[ $? != 0 ]]
then
#Add the path since it was not found
GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
fi
fi
done
#Loop root path array
for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
do
#CD into root path
cd $val
#Maven call to clean install
mvn -DskipTests=true --errors -T 8 -e clean install
#CD back up before next project
cd ../../
done
添加回答
舉報