天天看點

基于Github搭建Maven倉庫的方法搭建過程總結

基于Github搭建Maven倉庫的方法

參考網址:

将新SSH密鑰添加到您的GitHub帳戶

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

基于Github搭建Maven倉庫的方法

https://www.jianshu.com/p/3111bcf96cdf

将現在的GitHub公鑰添加到網站上

https://help.github.com/articles/authorizing-an-ssh-key-for-use-with-a-saml-single-sign-on-organization/

生成新的SSH密鑰并将其添加到ssh-agent

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent

1. 将SSH密鑰複制到剪貼闆。

Shell指令行下,将公鑰複制到剪貼闆

$ pbcopy < ~/.ssh/id_rsa.pub

  1. 将SSH密鑰複制到剪貼闆。如果您的SSH密鑰檔案的名稱與示例代碼不同,請修改檔案名以比對目前設定。複制密鑰時,請勿添加任何換行符或空格。
    $ pbcopy < ~/.ssh/id_rsa.pub 
    #将id_rsa.pub檔案的内容複制到剪貼闆
               
    提示:如果

    pbcopy

    不起作用,您可以找到隐藏

    .ssh

    檔案夾,在您喜歡的文本編輯器中打開檔案,然後将其複制到剪貼闆。
  2. 在任意頁面的右上角,單擊您的個人資料照片,然後單擊“設定”。
  3. 在使用者設定側欄中,單擊SSH和GPG密鑰。
  4. 單擊“ 建立SSH密鑰”或“ 添加SSH密鑰”。
  5. 在“标題”字段中,為新密鑰添加描述性标簽。例如,如果您使用的是個人Mac,則可以将此鍵稱為“Personal MacBook Air”。
  6. 将密鑰粘貼到“密鑰”字段中。
  7. 單擊“ 添加SSH密鑰”。 
  8. 如果出現提示,請确認您的GitHub密碼。

生成新的SSH密鑰并将其添加到ssh-agent

在将新的SSH密鑰添加到ssh-agent以管理密鑰之前,您應該檢查現有的SSH密鑰并生成新的SSH密鑰。将SSH密鑰添加到代理時,請使用預設的macOS 

ssh-add

指令,而不是macports,homebrew或其他外部源安裝的應用程式。

  1. 在shell背景啟動ssh-agent。
    $ eval "$(ssh-agent -s)" 
    #ssh-agent pid 59566
               
  2. 如果您使用的是macOS Sierra 10.12.2或更高版本,則需要修改

    ~/.ssh/config

    檔案以自動将密鑰加載到ssh-agent中并在密鑰鍊中存儲密碼。
    Host * 
    AddKeysToAgent yes 
    UseKeychain yes 
    IdentityFile ~/.ssh/id_rsa
               
  3. 将SSH私鑰添加到ssh-agent并将密碼存儲在密鑰鍊中。如果使用其他名稱建立密鑰,或者要添加具有不同名稱的現有密鑰,請将指令中的id_rsa替換為私鑰檔案的名稱。
    $ ssh-add -K ~/.ssh/id_rsa
               
    注意:該

    -K

    選項是Apple的标準版本

    ssh-add

    ,當您向ssh-agent添加ssh密鑰時,它會将密碼鍊存儲在您的鑰匙串中。

    如果您沒有安裝Apple的标準版本,則可能會收到錯誤消息。有關解決此錯誤的詳細資訊,請參閱“ 錯誤:ssh-add:非法選項 - K”。

  4. 将SSH密鑰添加到您的GitHub帳戶。

添加密鑰時的錯誤資訊:git id_rsa are too open檔案權限過大的解決方法

添加密鑰時的密鑰的檔案的權限應為700.

1、檔案屬性,即檔案的類型/讀/寫/執行等權限,共10個字元。

  • 第一個字元表示類型,後9個字元分3組,表示該檔案對于目前使用者(user)、目前使用者所在組(group)、其他使用者(other)的讀/寫/執行權限。
  • rwx:代表屬主權限,-代表無權限;r代表具有可讀權限; w代表具有可寫權限;x代表具有可執行權限
# 修改(~)個人目錄下的 .ssh 檔案夾中的密鑰權限為700
$ chmod 700 ~/.ssh/id_rsa
           

使用ssh -T [email protected]檢查密鑰和公鑰是否加載成功。

$ ssh -T [email protected]
Hi vcfriend! You've successfully authenticated, but GitHub does not provide shell access.
嗨,我的朋友!您已經成功地進行了身份驗證,但GITHUB不提供shell通路。
           

檢視遠端位址

git remote –v

檢視配置

git config --list

git remote –v       # 檢視遠端位址
 git config --list   # 檢視配置 
 git add .           # 暫存所有的更改
 git checkout .      # 丢棄所有的更改
 git status          # 檢視檔案狀态
 git commit -m "本次要送出的概要資訊"    # 送出
           

重點需要檢查的資訊

user.name=“github使用者名”

user.email=”使用者郵箱“

remote.origin.url=https://github.com/“使用者名”/maven

以下設定有誤時會出現以下錯誤資訊

fatal: Could not read from remote repository.的解決辦法

密鑰沒有添加成功git指令時可能會出現的錯誤資訊

Permission denied (publickey). fatal: Could not read from remote respository.解決辦法

搭建過程

  1. 利用github網站中建立一個新的倉庫,記下倉庫位址:

    [email protected]:${github_account}/maven.git

  2. 進入 ${HOME}/.m2/repository/,初始化git本地倉庫,添加員段位址。
$ cd ~/.m2/repository
$ git init
$ git remote add origin [email protected]:"使用者名"/maven.git
# 初始化本地倉庫,将本地倉庫上傳至遠端倉庫
           
  1. 建立.gitignore 将檔案比對符*加入其中, 并将.gitignore送出git本地倉庫master分支
$ echo "*" >> .gitignore
$ git add .gitgnore
$ git commit -m 'add .gitignore by ignoring all'
           
  1. 分别建立分支snapshot與release并push至遠端倉庫,用于釋出不同狀态的artifects,預設情況切換至snapshot
$ git branch snapshot
$ git branch release
$ git push origin snapshot
$ git push origin release
$ git checkout snapshot
           
  1. 當開發完成釋出新的artifects(例如com.github.${github_account}:${artifactId}:${version})時,首先利用mvn install 将artifects安裝至本地maven倉庫中 ~/.m2/repositor
$ cd ${project_root}
$ mvn install
           

然後,将需要釋出對應版本的artifects所聞送出至本地git倉庫中,然後push至對應的分支snapshot 或 release.

$ cd ~/.m2/repository
$ git add -f com/github/${github_account}/${artifactId}/${version}
$ git commit -m 'snapshot of com.github.${github_account}:${artifactId}:${version}'
$ git push origin snapshot
           
  1. 在pom.xml中使用maven artifact添加以下配置:
<project>
<!--Add repositories "添加自己的倉庫位址"-->
    <repositories>
        <repository>
            <id>haoch-maven-snapshot-repository</id>
            <name>haoch-maven-snapshot-repository</name>
            <url>https://raw.github.com/${github_account}/maven/snapshot/</url>
        </repository>
        <repository>
            <id>haoch-maven-release-repository</id>
            <name>haoch-maven-release-repository</name>
            <url>https://raw.github.com/${github_account}/maven/release/</url>
        </repository>
    </repositories>
<!-- Add dependencies "添加項目依賴"-->
    <dependencies>
        <dependency>
            <artifactId>${artifactId}</artifactId>
            <groupId>com.github.${github_account}</groupId>
            <version>${version}</version>
        </dependency>
    </dependencies>
</project>
           

總結

Github 目前為止也許是最好的代碼托管服務和社交程式設計平台,擁有非常好的開源分享文化,在這裡分享可複用的maven artifact自然也是最佳選擇。

Git原生提供的強大版本控制能力,在日常開發中必不可少,加上Github免費的git repository的靜态raw通路服務,Github作為maven remote repository可以和日常開發工作有效的融合。

作者:Devid

連結:https://www.jianshu.com/p/3111bcf96cdf

來源:簡書

簡書著作權歸作者所有,任何形式的轉載都請聯系作者獲得授權并注明出處。