在前一篇文章「架設自己的 Maven Repository Server(一):使用 Nexus 架設 Maven Repository Server」中
已經用 Nexus 建好一台非公開的 Maven Repository Server
接下來在這篇中就要把專案發佈到 Nexus 上了。
在 Nexus 上建立並設定使用者
- 在前一篇文章「架設自己的 Maven Repository Server(一):使用 Nexus 架設 Maven Repository Server」完成後,可以從 http://HOST_NAME:8081/nexus 進入 Nexus OSS 的介面。
- 以預設的管理員帳號 admin / admin123 登入 Nexus。
- 在左手邊的選單中,選擇 Security → Users,進入使用者管理介面。
- 點選 Add... → Nexus User 新增一個使用者,其中 Role Management 的部份,可以參考 deployment 這個使用者的權限,給予「Repo: All Repositories (Full Control)」和「Nexus Deployment Role」兩種角色。
設定專案的 Artifact 以及登入資訊
設定專案的 pom.xml
因為在有自建的 Nexus 服務的情況下,要讓專案去跟 Nexus 存取,而非跟 Default Maven Central 存取 因此要在專案的 pom.xml 上先做一些設定。- 設定 Nexus Repository 的路徑
12345678910111213141516171819<
project
>
<
repositories
>
<
repository
>
<
id
>maven-releases</
id
>
</
repository
>
</
repositories
>
<
distributionManagement
>
<
repository
>
<
id
>maven-releases</
id
>
</
repository
>
<
snapshotRepository
>
<
id
>maven-snapshots</
id
>
</
snapshotRepository
>
</
distributionManagement
>
</
project
>
設定電腦上的 Repository 登入資訊
在 Maven 的設計中,Repository 是需要驗證的,不過驗證的資訊不會寫在 pom.xml 上,畢竟 Artifact 本身可能是一個公開的 Artifact。因此會讓使用者將驗證資訊寫在自己的電腦上,在 build 的階段中,Maven 會自動去讀取設定。
- 依照官方文件描述,在使用者資料夾內的 ../.m2/settings.xml 檔案中寫下以下的資訊:
1234567891011121314<
settings
>
<
servers
>
<
server
>
<
id
>maven-releases</
id
>
<
username
>your-account-1</
username
>
<
password
>your-password-1</
password
>
</
server
>
<
server
>
<
id
>maven-snapshots</
id
>
<
username
>your-account-2</
username
>
<
password
>your-password-2</
password
>
</
server
>
</
servers
>
</
settings
>
其中上述的設定中,是指定當 Maven 遇到 ID 為 maven-releases 時,會使用 your-account-1 / your-password-1 登入
而當遇到 ID 為 maven-snapshots 時,則會使用 your-account-2 / your-password-2 登入。
將專案發佈到 Nexus 上
最後要將專案發佈出去時,只需要執行以下的指令即可!1 |
mvn clean deploy |
1 |
mvn clean deploy -Dmaven. test .skip= true |
參考資料:
沒有留言:
張貼留言