JAR部署后自动更新Maven依赖项 [英] Automatically update Maven dependencies after JAR deployment

查看:537
本文介绍了JAR部署后自动更新Maven依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Maven项目,在POM.xml文件中定义了一些依赖项. 这些依赖项通常每个月都有较新的版本,因此我想部署一个JAR文件,该文件可以在每次启动时自动检查这些依赖项的最新版本(而无需重新构建Java Maven项目).

I have a Java Maven project with some dependencies defined in the POM.xml file. These dependencies often have newer versions every month, so I would like to deploy a JAR file that automatically checks the latest versions of those dependencies in each startup (without re-building the Java Maven project).

是否可以使用Maven做到这一点?

Is it possible to achieve that with Maven?

我知道版本Maven插件对于下载最新版本的Maven插件很有用.依赖关系,但仅当重建"项目时(不在部署的JAR中).我也知道我可以使用像这样的表达式:

I know that the Versions Maven Plugin is useful to download the latest versions of dependencies, but only when "re-building" the project (not in a deployed JAR). I also know that I can use expressions like:

<version>[1.8,]</version>

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

But, again, these dependencies are only downloaded after building the project. I want to update dependencies automatically every time the user launches the application.

更新:

我要自动更新的依赖项是"selenium-chrome-driver".我的应用程序使用Chrome驱动程序来启动Google Chrome浏览器.

The dependency I want to automatically be updated is "selenium-chrome-driver". My application uses Chrome Driver to launch the Google Chrome browser.

问题是Chrome驱动程序每隔几个月更新一次,而旧版本则过时".结果,几个月后,已部署的JAR尝试使用旧版的Chrome驱动程序启动浏览器,但该浏览器无法正常工作.因此,我需要自动更新此依赖关系.否则,我将不得不每X个月部署一个新的JAR.

The problem is that Chrome Driver is updated every few months, and the older versions become "outdated". As a result, after a few months, the deployed JAR tries to launch the browser with an older version of Chrome Driver and it doesn't work. For that reason, I need to automatically update this dependency. Otherwise, I would have to deploy a new JAR every X months.

推荐答案

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

I had same problem for years, there is a library to do this, https://github.com/bonigarcia/webdrivermanager , but I didn't try it myself

当前正在使用此脚本(ubuntu)

Currently am using this 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

这篇关于JAR部署后自动更新Maven依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆