在JAR部署后自动更新Maven依赖项

时间:2014-05-06 14:07:47

标签: java maven deployment dependencies version

我有一个Java Maven项目,其中包含在POM.xml文件中定义的一些依赖项。 这些依赖项通常每个月都有更新的版本,所以我想部署一个JAR文件,在每次启动时自动检查这些依赖项的最新版本(无需重新构建Java Maven项目)。

是否有可能通过Maven实现这一目标?

我知道Versions Maven Plugin对于下载最新版本的依赖项很有用,但仅限于“重新构建”项目(而不是在已部署的JAR中)。我也知道我可以使用如下表达式:

<version>[1.8,]</version>

但是,同样,这些依赖项仅在构建项目后下载。我希望每次用户启动应用程序时自动更新依赖项。

更新

我想要自动更新的依赖项是“selenium-chrome-driver”。我的应用程序使用Chrome驱动程序启动Google Chrome浏览器。

问题是Chrome驱动程序每隔几个月更新一次,旧版本变得“过时”。因此,几个月后,部署的JAR尝试使用较旧版本的Chrome驱动程序启动浏览器,但它无效。出于这个原因,我需要自动更新此依赖项。否则,我将不得不每X个月部署一个新的JAR。

1 个答案:

答案 0 :(得分:0)

多年来,我一直遇到相同的问题,有一个https://github.com/bonigarcia/webdrivermanager库可以做到这一点,但是我自己没有尝试过

当前正在使用此script(ubuntu)

# https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5
# https://gist.github.com/birdsarah/23312f1d7cbd687ac376c95662254773

# This script checks & downloads latest chromeDriver and geckoDriver IF needed.
# New drivers are extracted and copied to $driversDestination
# IMPORTANT: Remember to change $driversDestination variable below to match your case
# You can call this script before launching your test suite so you always get latest drivers each run

os=linux64
driversDestination=../dependencies/browser-drivers/

if [ -e chromedriver_last.txt ]
then
    chromedriver_last_download=`cat chromedriver_last.txt`
fi

chromedriver_latest_version=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
if [ "$chromedriver_last_download" = "$chromedriver_latest_version" ]; then
    echo "Already has last chrovedriver version" $chromedriver_latest_version
else
    echo "Updating chromedriver from " $chromedriver_last_download "to" $chromedriver_latest_version
    wget -N http://chromedriver.storage.googleapis.com/$chromedriver_latest_version/chromedriver_$os.zip -O chromedriver_linux64.zip
    echo "$chromedriver_latest_version" > "chromedriver_last.txt"
    unzip -o chromedriver_$os.zip -d $driversDestination
    rm chromedriver_$os.zip
fi

if [ -e geckodriver_last.txt ]
then
    geckodriver_last_download=`cat geckodriver_last.txt`
fi

geckodriver_latest_version=`curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r ".tag_name"`

if [ "$geckodriver_last_download" = "$geckodriver_latest_version" ]; then
    echo "Already has last geckodriver version" $geckodriver_latest_version
else
    echo "Updating geckodriver from " $geckodriver_last_download "to" $geckodriver_latest_version
    wget https://github.com/mozilla/geckodriver/releases/download/$geckodriver_latest_version/geckodriver-$geckodriver_latest_version-$os.tar.gz -O geckodriver.tar.gz
    echo "$geckodriver_latest_version" > "geckodriver_last.txt"
    tar -xvzf geckodriver.tar.gz
    rm geckodriver.tar.gz
    chmod +x geckodriver
    mv geckodriver $driversDestination
fi
相关问题