亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Git 合并/拉取后使用 Maven 進行部分全新安裝

Git 合并/拉取后使用 Maven 進行部分全新安裝

慕婉清6462132 2022-01-19 17:01:41
使用終端,是否可以清理和安裝 POM 項目中在 a 之后發生更改的項目,git merge/pull換句話說,自上次全新安裝以來的更改?編輯感謝 VonC 的回答,我已經完成了一個可以滿足我要求的腳本。有關詳細信息,請參閱下面的答案。
查看完整描述

2 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

由于您可以檢測到pom.xml兩次提交之間的更改列表:

git diff --name-status <commit1> <commit2>

(另見“ Git pull 后的細節變化”)

,您可以制作一個腳本,該腳本將為每個模塊執行一個mvn clean install.


查看完整回答
反對 回復 2022-01-19
?
鴻蒙傳說

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


查看完整回答
反對 回復 2022-01-19
  • 2 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號