github上搭建代碼庫

通過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

  1. 登陸到github,然後選擇settings
    在這裏插入圖片描述
  2. 創建key
    在這裏插入圖片描述
    在這裏插入圖片描述
    步驟五:配置賬號
  3. 配置用戶名
    git config --global user.name “githubtest”
  4. 配置郵箱(建議用註冊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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章