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:
- Nếu đã cài đặt Maven cục bộ, chỉnh sửa tệp
${MAVEN_HOME}/conf/settings.xml: - 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 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>
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:
- Chọn dự án, nhấn chuột phải chọn
Run Maven → deploy - 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.