Automatically update Maven dependencies after JAR

2019-07-19 16:16发布

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).

Is it possible to achieve that with Maven?

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.

UPDATE:

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

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.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-19 16:41

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

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
查看更多
登录 后发表回答