Last active
April 4, 2017 08:42
-
-
Save waleedsamy/f52e1d7f827a1595d7879ae6f73319c1 to your computer and use it in GitHub Desktop.
This script will fetch an artifact from a Nexus server(or any other repository) using maven.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Argument = -h -v -i groupId:artifactId:version -c classifier -p packaging | |
| #shopt -o -s xtrace | |
| usage() | |
| { | |
| cat <<EOF | |
| usage: $0 options | |
| This script will fetch an artifact from a Nexus server using maven, please make sure maven 3 is installed. | |
| OPTIONS: | |
| -h Show this message | |
| -v Verbose | |
| -i GAV coordinate groupId:artifactId:version | |
| -c Artifact Classifier | |
| -p Artifact Packaging | |
| EOF | |
| } | |
| # Read in Complete Set of Coordinates from the Command Line | |
| GROUP_ID= | |
| ARTIFACT_ID= | |
| VERSION= | |
| CLASSIFIER="" | |
| PACKAGING=jar | |
| REPO=http://nexus.office.traffics-switch.de:8081/repository/maven-snapshots | |
| VERBOSE=0 | |
| while getopts "hvi:c:p:" OPTION | |
| do | |
| case $OPTION in | |
| h) | |
| usage | |
| exit 1 | |
| ;; | |
| i) | |
| OIFS=$IFS | |
| IFS=":" | |
| GAV_COORD=( $OPTARG ) | |
| GROUP_ID=${GAV_COORD[0]} | |
| ARTIFACT_ID=${GAV_COORD[1]} | |
| VERSION=${GAV_COORD[2]} | |
| IFS=$OIFS | |
| ;; | |
| c) | |
| CLASSIFIER=$OPTARG | |
| ;; | |
| p) | |
| PACKAGING=$OPTARG | |
| ;; | |
| v) | |
| VERBOSE=1 | |
| ;; | |
| ?) | |
| usage | |
| exit | |
| ;; | |
| esac | |
| done | |
| if [[ -z $GROUP_ID ]] || [[ -z $ARTIFACT_ID ]] || [[ -z $VERSION ]] | |
| then | |
| echo "BAD ARGUMENTS: Either groupId, artifactId, or version was not supplied" >&2 | |
| usage | |
| exit 1 | |
| fi | |
| mvn -U dependency:get \ | |
| -Dartifact=$GROUP_ID:$ARTIFACT_ID:$VERSION:$PACKAGING:$CLASSIFIER \ | |
| -DremoteRepositories=$REPO \ | |
| -Ddest=./$ARTIFACT_ID.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment