准备
申请Github帐号并配置ssh public key: http://blog.youkuaiyun.com/psu_vjd/article/details/54317621
安装Git工具: http://blog.youkuaiyun.com/laiahu/article/details/7516939
安装Maven工具: http://blog.youkuaiyun.com/javaee_ssh/article/details/43774583
搭建过程
- 利用github网站中创建一个新的仓库,记下仓库地址:
git@github.com:${github_account}/${maven-repo}.git
- 初始化git本地仓库,添加远端git仓库地址
cd ${git_repo_path} git init git remote add origin git@github.com:${github_account}/${maven-repo}.git
- 创建.gitignore 并提交git本地仓库master分支
echo "" >.gitignore git add -f .gitignore git commit -m 'add .gitignore' && git push origin master
- 创建分支snapshot并push到远程分支
git branch snapshot git push origin snapshot git checkout snapshot
- 当开发完成后发布新的artifects(例如:${groupId}:${artifactId}:${version}),首先利用mvn deploy将artifects发布至刚刚创建的git仓库中
其中,${distribute_id}对应pom文件中distributionManagement/repository/id,也可随意填写mvn deploy -DaltDeploymentRepository=${distribute_id}::default::file:${git_repo_path}
- 将需要发布对应版本的artifects提交至本地git仓库中,然后push至对应的分支snapshot
cd ${git_repo_path} git checkout snapshot git add -f ${groupId}/${artifactId}/${version} git commit -m 'deploy ${groupId}:${artifactId}:${version}' git push origin snapshot
- 在settings.xml中添加如下配置:
<?xml version="1.0"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>${github_account}-github-maven</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.7</jdk> </activation> <repositories> <repository> <id>${github_account}-maven-snapshot-repository</id> <name>${github_account}-maven-snapshot-repository</name> <url>https://raw.githubusercontent.com/${github_account}/${maven-repo}/snapshot</url> </repository> </repositories> </profile> </profiles> <pluginGroups> <pluginGroup>org.apache.maven.plugins</pluginGroup> </pluginGroups> <activeProfiles> <activeProfile>${github_account}-github-maven</activeProfile> </activeProfiles> </settings>
- 在pom.xml中使用上传的jar包:
<dependencies> <dependency> <groupId>${groupId}</groupId> <artifactId>${artifactId}</artifactId> <version>${version}</version> </dependency> </dependencies>