通过github可以管理代码,还可以作为maven仓库
一:配置SSH Keys连接GitHub
步骤一:下载安装git bash
步骤二:删除本机已有的ssh key
打开git bash -> cd .ssh
删除ssh目录下所有文件
步骤三:生成新定ssh key
cd ~
ssh-keygen -t rsa -C “有效邮箱”
在ssh目录下成功生成了公钥和密钥
pwd查看key在本地位置,默认是在c:/user/用户/.ssh
步骤四: 把ssh key添加到github
- 登陆到github,然后选择settings
- 创建key
步骤五:配置账号 - 配置用户名
git config --global user.name “githubtest” - 配置邮箱(建议用注册giuhub的邮箱)
git config --global user.email “[email protected]”
步骤六:测试sshkey是否配置成功
在git bash上:ssh -T [email protected]
设置成功
二:将本地项目通过SSH push到GitHub
步骤一:在github上创建一个仓库
步骤二:上传本地的代码
使用git客户端clone仓库到本地:
然后可以在仓库中创建代码并提交
三:搭建maven仓库
步骤一:发布项目到本地maven仓库
mvn deploy -DaltDeploymentRepository=id::default::file:本地路径
步骤二:把本地仓库文件提交到github上
1.进入本地仓库根目录
进入git bash然后git init
2. git add
例如添加com.tdemo.found项目
git add ./com/tdemo/found
3. 提交日志:git commit -m ‘deploy myproect’
4. 指定github仓库:
git remote add origin github仓库url
5:push
git push origin master
如果报错: failed to push some refs to …
那么在第5之前执行:git pull --rebase origin master
然后再执行5
步骤三:检查github
步骤四: 再项目中引用发布到github上的项目
因为github使用了raw.githubusercontent.com这个域名用于raw文件下载。所以使用这个maven仓库
再pom.xml中或者settings.xml中加入以下代码:
<repositories>
<repository>
<id>任意id</id>
<url>https://raw.githubusercontent.com/仓库路径</url>
</repository>
</repositories>
例如:我现在要引用我的以下仓库中的包:
那么应该这样配置:
<repositories>
<repository>
<id>githubres</id>
<url>https://raw.githubusercontent.com/github的账号/mavenrepository/master</url>
</repository>
</repositories>
如果使用分支test,则把master改为test即可
四:用到的maven命令
1:使用deploy发布jar
mvn deploy:deploy-file -DgroupId=groupid -DartifactId=artifactId -Dversion=版本
-Dpackaging=jar -Dfile=E:\test.jar -Durl=私服url -DrepositoryId=thirdparty(在 settings.xml中配置的私服id)
例如:
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
2:使用deploy发布项目到本地(不存在现有的jar)
mvn deploy -DaltDeploymentRepository=id::default::file:本地路径
3:使用mvn install
mvn install:install-file -Dfile=jar的路径
-DgroupId=groupId
-DartifactId=artifactId
-Dversion=1.0.0 -Dpackaging=jar
参考:
https://www.cnblogs.com/hukai46/p/5489631.html
https://blog.csdn.net/hengyunabc/article/details/47308913
https://blog.csdn.net/sunxiaoju/article/details/85331265