- 下载解压 maven
- 在
.bash_profile/.bashrc/.zshrc
中添加 maven 路径
export M2_HOME=/usr/local/apache-maven-3.8.3
export PATH=$PATH:$M2_HOME/bin
部署文件到nexus的原始命令如下
mvn -s ~/deploy/settings.xml \
deploy:deploy-file \
-DgroupId=com.xxx.android -DartifactId=artifact-name -Dversion=1.1.0 \
-Dpackaging=aar -Dfile=~/path/to/aar/file-name.aar \
-Durl=http://private-nexus.com/content/repositories/thirdparty/ -DrepositoryId=thirdparty
需要配置文件存放用户名和密码,所以封装为简单shell脚本
#!/usr/bin/env bash
if [[ $# = 0 ]]; then
echo 'Usage: bash deploy.sh groupId artifactId version packType filePath';
exit 1;
fi
cmdDir=`dirname $0`
groupId=$1
artifactId=$2
version=$3
packType=$4
filePath=$5
# 部署文件到nexus的maven命令
mvn -s $cmdDir/settings.xml deploy:deploy-file \
-DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version \
-Dpackaging=$packType -Dfile=$filePath \
-Durl=http://private-nexus.com/content/repositories/thirdparty/ -DrepositoryId=thirdparty
# 输出gradle需要的工件信息
# com.xxx.android:artifact-name:1.1.0
echo "gradle dependency: $groupId:$artifactId:$version"
脚本中的settings.xml
和脚本在相同目录,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<settings
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<servers>
<server>
<id>thirdparty</id>
<username>your_name</username>
<password>your_pwd</password>
</server>
</servers>
</settings>
执行举例
bash deploy.sh com.xxx.android artifact-name 1.1.0 aar /path/to/aar/file-name.aar