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

标签 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 Driver 每隔几个月更新一次,旧版本变得“过时”。结果,几个月后,部署的 JAR 尝试使用旧版本的 Chrome 驱动程序启动浏览器,但它不起作用。因此,我需要自动更新此依赖项。否则,我将不得不每 X 个月部署一个新的 JAR。

最佳答案

多年来我一直有同样的问题,有一个图书馆可以做到这一点,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

关于java - JAR 部署后自动更新 Maven 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23497066/

相关文章:

java - 使用基于 Java 的 selenium 时是否有等价的 waitForAngular() ?

java - 从 Guava 的 Splitter 创建一个 String[]

java:comp/env 未绑定(bind)

java - 如何将可执行JAR文件打包成EXE

android - 部署 Android 应用程序 Qt 5.1

java - 图像不显示..Java

java.lang.NoClassDefFoundError : org/hibernate/cache/EntityRegion configuring EHCache

java - CouchDB Java 库由 Maven 下载,但不被 IntelliJ 识别

java - Maven环境设置Windows 7错误

deployment - LiveRebel 更新策略