Đăng ký dự án Maven (tệp jar) lên kho Nexus riêng

Mục đích triển khai

Sau khi hoàn thành phát triển ứng dụng, cần triển khai phiên bản dự án lên kho lưu trữ Nexus cục bộ.

Quy trình thực hiện

Cấu hình tệp settings.xml của Maven

Thực hiện các thao tác sau:

  1. Nếu đã cài đặt Maven cục bộ, chỉnh sửa tệp ${MAVEN_HOME}/conf/settings.xml:
  2. <!-- Cấu hình thông tin xác thực kho riêng -->
    <servers>
      <server>
        <id>thu-phat</id>
        <username>admin</username>
        <password>admin123</password>
      </server>
      <server>
        <id>ban-nen</id>
        <username>admin</username>
        <password>admin123</password>
      </server>
    </servers>
    
    <!-- Cấu hình kết nối kho lưu trữ -->
    <profiles>
      <profile>
        <id>dev</id>
        <repositories>
          <repository>
            <id>nexus-local</id>
            <url>http://ip:port/nexus/content/groups/public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </repository>
        </repositories>
        
        <pluginRepositories>
          <pluginRepository>
            <id>public-plugins</id>
            <name>Kho tiện ích</name>
            <url>http://ip:port/nexus/content/groups/public/</url>
          </pluginRepository>
        </pluginRepositories>
      </profile>
      
      <profile>
        <id>internet</id>
        <repositories>
          <repository>
            <id>nexus-aliyun</id>
            <name>Kho Aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <snapshots><enabled>false</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
          </repository>
        </repositories>
      </profile>
    </profiles>
  3. Trường hợp chưa cài Maven cục bộ, thực hiện cấu hình tương tự trong môi trường phát triển như IntelliJ IDEA hoặc Eclipse.

Cấu hình tệp pom.xml dự án

Thêm đoạn cấu hình sau vào tệp pom.xml:

<distributionManagement>
  <repository>
    <id>thu-phat</id>
    <name>kho-thu-phat</name>
    <url>http://ip:port/nexus/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
    <id>ban-nen</id>
    <name>kho-ban-nen</name>
    <url>http://ip:port/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
</distributionManagement>

Triển khai dự án

Ví dụ sử dụng IntelliJ IDEA:

  1. Chọn dự án, nhấn chuột phải chọn Run Maven → deploy
  2. Hoặc qua thanh bên chọn Maven → Lifecycle → deploy

Lưu ý: Đảm bảo không tồn tại gói có cùng tên và phiên bản trong kho, nếu không sẽ gặp lỗi Bad Request: 400.

Thẻ: Maven nexus pom.xml settings.xml triển-khai

Đăng vào ngày 7 tháng 6 lúc 20:53