Build internal maven repositories
Installation of management tool
Choose sonatype nexus repository manager to bulid internal maven repositories.
Download link: https://help.sonatype.com/repomanager3/product-information/download
Select a tar match your system and execute following commands:
1 | wget https://download.sonatype.com/nexus/3/nexus-3.41.1-01-unix.tar.gz |
Because use root to start nexus, check the log:
1 | tail -f /root/sonatype-work/nexus3/log/nexus.log |
application is started
1 | ------------------------------------------------- |
But we want this application run as service, so do more configuration for systemd, create a file /etc/systemd/system/nexus.service
contains:
1 | [Unit] |
then enable and start nexus:
1 | sudo systemctl daemon-reload |
after that management tool installation finished, let’s start to build internal maven repositories.
Create private repository
First, access sonatype nexus by 8081 port and finish the wizard.
Repository types
According to nexus docs, there are several proxy types for nexus:
- Proxy repository: is a type linked to remote repository, which act as cache for the local request
- Hosted repository: local stored and follow maven policy
- Repository group: combine multi repositories as one
So our usage, we choose maven2 hosted repository to publish our own jar.
Following configurations are used for this repository:
1 | format: maven2 |
And try to upload first jar to our hosted repository
Accesshttp://your_nexus_address/#browse/upload:your_repo
this page to uplaod jar with group id and artifact id.
Then, change pom.xml to enable the repository:
1 | <repositories> |
But if use maven3 need to update settings to allow http access.
1 | <mirror> |
Test mvn install the lib is download as expected.
Deploy project to the repository
Add distribution management into your pom.xml
1 | <distributionManagement> |
to set which repo address your deployment should go, then add server related setttings to your .m2/settting.xml
1 | <server> |
Then use mvn deploy
to finish upload.
There are some errors during the configuration phase.
Error status code 401, means authentication failure, use
mvn -X
to check[DEBUG] Reading global settings from /opt/maven/conf/settings.xml
[DEBUG] Reading user settings from /root/.m2/settings.xml
two configuration files are used, change the global one with the sever section fix the issue.Error status code 400, nexus repository should change the deployment policy to allow redeploy