-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmvn-install.sh
executable file
·56 lines (53 loc) · 1.89 KB
/
mvn-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
#
# Install local jar files into Maven repository. The artifact name would be same
# as the filename minus the extension.
# :Author: Zemian Deng
# :Date: 2013/06/17
#
# Usage:
# # Print as maven dependency used in pom file
# mvn-install.sh mygroup 1.0.0 lib/*.jar
#
# # Install jar files into local maven repo
# RUN_TYPE=install mvn-install.sh mygroup 1.0.0 lib/*.jar
#
# # Deploy jar files into remote maven repo
# export REPO_URL=http://localhost/nexus/content/repositories/thirdparty
# RUN_TYPE=deploy mvn-install.sh mygroup 1.0.0 lib/*.jar
#
# Capture command arguments and options
GROUP=$1
shift
VERSION=$1
shift
FILES="$@"
if [[ "$GROUP" == "" || "$VERSION" == "" || "$FILES" == "" ]]; then
printf "ERROR: invalid arguments: GROUP VERSION FILES...\n"
exit 1
fi
RUN_TYPE=${RUN_TYPE:="print"} # values: print|install|deploy
REPO_ID=${REPO_ID:="nexus-server"} # Id defined in user's settings.xml for authentication
REPO_URL=${REPO_URL:="http://localhost/nexus/content/repositories/thirdparty"}
# For each file, perform action based on run type.
for FILE in $FILES; do
ARTIFACT=`basename $FILE '.jar'`
if [[ "$RUN_TYPE" == "deploy" ]]; then
printf "Deploying file=$FILE as artifact=$ARTIFACT to repo=$REPO_URL\n"
mvn deploy:deploy-file \
-DrepositoryId=$REPO_ID -Durl=$REPO_URL \
-DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar \
-Dfile=$FILE
elif [[ "$RUN_TYPE" == "install" ]]; then
printf "Installing file=$FILE as artifact=$ARTIFACT\n"
mvn install:install-file \
-DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar \
-Dfile=$FILE
elif [[ "$RUN_TYPE" == "print" ]]; then
printf " <dependency>\n"
printf " <groupId>$GROUP</groupId>\n"
printf " <artifactId>$ARTIFACT</artifactId>\n"
printf " <version>$VERSION</version>\n"
printf " </dependency>\n"
fi
done